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:
Local Build Success: We’ve tested the build process locally using next build and vercel build, and both work without issues.
Vercel Logs: The Vercel logs don’t provide any specific error messages that could help identify what’s going wrong.
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.
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.
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.
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
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
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?
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.
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: