Build Works Locally but Fails in Vercel Production

Hi Vercel Community,

I’m encountering an issue where my application works fine locally (both with Next.js build and Vercel build), but fails in the production deployment on Vercel.

Problem Overview:

  • The build process completes successfully when running locally using next build and vercel build.
  • The same build works fine in the local environment, but once deployed to Vercel, the build fails.
  • There is no clear error message in the Vercel build logs, which makes it difficult to pinpoint the exact cause of the issue.

Behavior in Production:

  • The application is deployed and accessible, but certain functionality fails to work as expected.
  • In particular, we are noticing issues related to downloading functionality, but we’re not sure if the problem is specifically with that or something else in the deployment.
  • The Vercel production logs show the following error message:

What We’ve Tried:

  1. Local Build Success: We’ve tested the build process locally using next build and vercel build, and both work without issues.
  2. Vercel Logs: The Vercel logs don’t provide any specific error messages that could help identify what’s going wrong.
  3. Environment Differences: We’ve ensured that the client-side environment (e.g., access to document and window) is properly checked, but the issue persists in production.

Repository:

You can find the repository here:
GitHub Repo URL

Request for Help:

Has anyone experienced a similar issue where the build works locally but fails in Vercel production without clear errors in the logs? Any guidance or suggestions on how to debug or resolve this would be greatly appreciated.

Thank you!

Thanks for sharing the repo, @hardikrathod123. I get the same error messages on a local build. There might be a missing dependency or file that wasn’t checked in to the remote repo.

All my commits are in sync and since its personal project I am keeping only one branch. so both remote and local would be in sync

There’s definitely something different about your local setup that allows it to work. I got the same error messages as your Vercel build when I tried to build it locally with npm run build.

ReferenceError: document is not defined at createTag and encountered errors on following paths: page: /

I see there are environment variables which I don’t have set in my copy. So this could be a case of missing environment variables. You can solve that by including the required environment variables in Project Settings.

It could be something else that is different on your computer. Possibly a globally installed package that needs to be added to the repo’s package.json

I have added environment variables in vercel as well.

I have deployed the project on netlify and its working with no issue.(so I am thinking issue maybe related to vercel)

if you are getting an error, were you able to navigate to which file/component is causing the error?

The issue seems to be reproducing with node version. I was running 20x in local and when I switched to 23x I also started getting the error.

1 Like

If someone could guide/hint me on what this issue could be related to so I could dig a little deeper and then I could create issue/PR on vercel/nextjs repo

CC @amyegan

I’m admittedly new to the Vercel ecosystem, but I’m finding that nothing seems to work as advertised. I’ve tried several starter projects based on the supplied templates, all of which fail immediately on deployment. What am I missing?

Which templates didn’t work for you? I can look into them and make sure they’re updated if anything needs to be fixed

I think I am facing the same/related issue. Last week I deployed a branch and it worked fine but today I made a small update (2 lines) and it caused a build error. I checked the source code of the deployment last week and it had the code referenced in the build error. Like the cases above it builds and runs locally without any issues.

What changed between the working deployment and the new deployment? That might narrow down the possible causes.

This change worked for me, but its strange that the build was successful on vercel previously with the require syntax. reactjs - error in react app vercel deployment. plugins: [require("tailwindcss-animate")] ERROR: ReferenceError: require is not defined - Stack Overflow

It might have been caused by a package update or the fairly recent upgrade to Node.js v22.

In any case, I’m glad you found a solution. Thanks for coming back here to share it!

I am facing the same error and the same issue, back to my website for some changes after 4 months and now its failing, the issue is not with the project local or global dependencies etc because the project works fine with netlify but fails on vercel.
screenshot of the error:

Can you share the deployment ID? You can visit the deployment in Vercel dashboard and find the ID in URL bar.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.