Error in nextjs production build (Just in production)

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

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:

  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.

Hi @gemss this seems to be an issue with your builder content for that model and not code. I used the 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.

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.

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.

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.

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.

Any update with this @ancheetah ?

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.

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

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

 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();

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

Ty

@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.