“RangeError: Invalid array length" During Vercel Build

Hi everyone,

I’m encountering an issue while deploying my Next.js project on Vercel. The build process fails with the following error:

Creating an optimized production build ...
uncaughtException RangeError: Invalid array length
    at Array.push (<anonymous>)
Error: Command "npm run build" exited with 1

I’ve tried the following troubleshooting steps but haven’t found a solution:

  • Cleared .next and node_modules, then reinstalled dependencies
  • Checked for any infinite loops or excessive recursion in my code
  • Ran npm run build locally, which works fine without errors

I’m using:

  • Next.js version: 15.2.2
  • Vercel deployment method: (GitHub integration, CLI, etc.)

Has anyone faced a similar issue or knows what might be causing this? Any guidance would be greatly appreciated!

Thanks in advance!

Hi @mikky15, sorry that you’re facing this issue. Is this a v0 created project? Can you share more information about what you’re doing the project and since when this error started popping?

Since you said npm run build works, do you only see the error on Vercel?

Hi @anshumanb,

Thanks for the response!

The error first started appearing on March 15th, 2025, after I made some changes to the code and tried deploying it to Vercel. I’m only encountering the error during deployment on Vercel, while the npm run build command works fine on my local machine.

Please let me know if you need any additional information to help troubleshoot!

Thanks!

Hi @mikky15, thanks for the information but without looking at the code it’s hard to debug this error. Can you please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.

1 Like

I ran into this as well in a large app. It’s not only during the build process, it can happen on the development server too.

This seems to be a node.js array length issue under the hood. Maybe something is tracking files/file changes?

The length limit in node.js seems to be a bit over 100 million, at least on my machine.