# Error in nextjs production build (Just in production)

**URL:** <https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710>\
**Category:** Technical Questions\
**Tags:** nextjs\
**Created:** [February 4, 2022, 2:40pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710 "2022-02-04T14:40:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gemss](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@gemss](https://forum.builder.io/u/gemss)\
**Post date:** [February 4, 2022, 2:40pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/1 "2022-02-04T14:40:24Z")

</div>

Hi!  
We are running our app with builder within a vercel deployment, directly forking nextjs-builder-io-landing-page builderio github template.

Well we have been doing builds and deploys for 3 months but yesterday without any change in the code, build process crashed (Im 100% sure that is not related to a code change because I have tried to build past versions of the code that where deployed without any problem in the past).  
By the way in development env everything work just fine.

This is the error we see in the build

```auto
info - Collecting page data  
[==] info - Generating static pages (26/35)undefined:1
Error: could not handle the request
^

SyntaxError: Unexpected token E in JSON at position 0
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (/Users/me/builderio_vercel_statics/.next/serverless/pages/[[...path]].js:29173:34)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

> Build error occurred
Error: Call retries were exceeded
    at ChildProcessWorker.initialize (/Users/me/builderio_vercel_statics/node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)
    at ChildProcessWorker._onExit (/Users/me/builderio_vercel_statics/node_modules/jest-worker/build/workers/ChildProcessWorker.js:275:12)
    at ChildProcess.emit (node:events:390:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) {
  type: 'WorkerError'
}

```

I have tried to debug and I found that the line that causes this problem is:

```auto
  const pages = await builder.getAll('static-pages', {
    options: { noTargeting: true },
    apiKey: builderConfig.apiKey,
  })

```

If I change the name of the model to other works ok…but we need this model, is where all the builder info and setup has been done. The env var is correct, I have tried also to hardcode it but same error.

Need some guidance here, I insist that is not code related since old versions do break also the build.

---

<div class="post-metadata">

**Author:** ![ancheetah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/ancheetah/32/751_2.png) [@ancheetah](https://forum.builder.io/u/ancheetah)\
**Post date:** [February 8, 2022, 8:16pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/2 "2022-02-08T20:16:21Z")

</div>

Hi @gemss this seems to be an issue with your builder content for that model and not code. I used the [next-js-simple](https://github.com/BuilderIO/builder/tree/main/examples/next-js-simple) starter to fetch the content from your `static-pages` model. When I ran the build locally this morning I added a console log after the `getAll()` fetch to view the static paths generated and saw that it tried to generate a path for `/ranking-test-valentin/**`. However, when I looked in your space I did not see any content for that URL so it is expected that the build would fail for an empty entry.

I have since not been able to reproduce the issue so it’s possible one of your users might be changing/testing content in your production space.

---

<div class="post-metadata">

**Author:** ![gemss](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@gemss](https://forum.builder.io/u/gemss)\
**Post date:** [February 10, 2022, 1:59pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/3 "2022-02-10T13:59:55Z")

</div>

We have been creating some wildcard urls based on builderio dynamic info fetching feature, but it seems that the content setup inside builder for this model blocks the build of the project.  
Any tip on how to fix this? For us is not super obvious what is happening in the “content side” of things that blocks everything. Having a model that works out of the box, but blocks the builds makes the process of adding new stuff really difficult.

---

<div class="post-metadata">

**Author:** ![gemss](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@gemss](https://forum.builder.io/u/gemss)\
**Post date:** [February 14, 2022, 9:00am UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/4 "2022-02-14T09:00:26Z")

</div>

Really weird, we did not change the urls that where failing but now they are working…we are confused with this. Could anyone clarify why this is failing sometimes? Or at least what can we do to debug and fix if the problem is on content side.

---

<div class="post-metadata">

**Author:** ![ancheetah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/ancheetah/32/751_2.png) [@ancheetah](https://forum.builder.io/u/ancheetah)\
**Post date:** [February 18, 2022, 7:15pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/5 "2022-02-18T19:15:05Z")

</div>

Hey @gemss, glad it’s working again. I am not able to reproduce the initial error anymore and I suspect it may have be something on the content side. If it occurs again, please let me know and I can try to investigate the root cause.

---

<div class="post-metadata">

**Author:** ![gemss](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@gemss](https://forum.builder.io/u/gemss)\
**Post date:** [February 23, 2022, 3:11pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/6 "2022-02-23T15:11:36Z")

</div>

Hi! Is happening again, we cant create new builds if we don’t unpublish the content, Is there any chance that we can locate where the problem is? We are more than happy to debug and try to fix it ourselves but since is related to the content/config and not to the code we don’t know how to debug this.

Our use case is basically a dynamic url with data binding.

---

<div class="post-metadata">

**Author:** ![gemss](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@gemss](https://forum.builder.io/u/gemss)\
**Post date:** [February 25, 2022, 8:10am UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/7 "2022-02-25T08:10:21Z")

</div>

Any update with this @ancheetah ?

---

<div class="post-metadata">

**Author:** ![ancheetah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/ancheetah/32/751_2.png) [@ancheetah](https://forum.builder.io/u/ancheetah)\
**Post date:** [February 25, 2022, 9:36pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/8 "2022-02-25T21:36:10Z")

</div>

Hi @gemss, if I copy your custom JS from the `/ranking/ **` entry into my own test space it builds fine on my end and I’m not able to reproduce the error. However, if I run a build on your `static-pages` model I do see the following errors thrown for two of your entries. It appears the `/ranking-staging/** ` entry is just a duplicate of `/ranking/**` though so this error is expected. I’ve escalated this with my team to see if we can investigate further.

 ![Screen Shot 2022-02-25 at 3.42.45 PM](https://us1.discourse-cdn.com/flex020/uploads/builder/original/2X/b/bec3595b80716abffd92995f0116a16157108bff.jpeg)

---

<div class="post-metadata">

**Author:** ![gemss](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@gemss](https://forum.builder.io/u/gemss)\
**Post date:** [February 28, 2022, 7:32am UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/9 "2022-02-28T07:32:45Z")

</div>

> [@ancheetah](#):
>
> odel I do see the following errors thrown for two of your entries. It appears the `/ranking-staging/**` entry is just a dup

Thanks @ancheetah we will be waiting to know how this can happen so we can prevent it

---

<div class="post-metadata">

**Author:** ![ancheetah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/ancheetah/32/751_2.png) [@ancheetah](https://forum.builder.io/u/ancheetah)\
**Post date:** [March 4, 2022, 8:04pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/10 "2022-03-04T20:04:20Z")

</div>

Hey @gemss, can you try wrapping your custom JS code with `isBrowser`?

```auto
 async function main () {
  if (Builder.isServer) {
    // Place any code here you want to only run on the server. Any  
    // data fetched on the server will be available to re-hydrate on the client
    // if added to the state object
  }

  if (Builder.isBrowser) {
    // Place code that you only want to run in the browser (client side only) here
    // For example, anything that uses document/window access or DOM manipulation
  }
}

export default main();

```

---

<div class="post-metadata">

**Author:** ![gemss](https://avatars.discourse-cdn.com/v4/letter/g/edb3f5/32.png) [@gemss](https://forum.builder.io/u/gemss)\
**Post date:** [March 14, 2022, 7:18am UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/11 "2022-03-14T07:18:08Z")

</div>

Hi @ancheetah definitely this helped, it would be great to have a post of a best practices around this within builder dynamic content.

Ty

---

<div class="post-metadata">

**Author:** ![ancheetah](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.builder.io/ancheetah/32/751_2.png) [@ancheetah](https://forum.builder.io/u/ancheetah)\
**Post date:** [March 15, 2022, 8:59pm UTC](https://forum.builder.io/t/error-in-nextjs-production-build-just-in-production/1710/12 "2022-03-15T20:59:02Z")

</div>

@gemss glad to hear it helped! I’ll mention this to our documentation team as well so that it is more clear. If your custom code works when wrapped in `isBrowser` this typically indicates there is something in your code that is browser specific. Builder runs custom JS server-side by default if not wrapped with `isBrowser`. So something in your code - maybe where you set the `url` variable or have `window.location.href` redirects - could have been failing on our servers because that information would only available client-side.
