I am facing deployment issues on Vercel, even though the same project works perfectly in my local environment.
- Local Environment:
• Running pnpm dev, pnpm build, and vercel dev works without any issues.
• The application builds and runs successfully locally.
- Vercel Deployment:
• The same project fails during the build process on Vercel.
• I’ve tested this by reverting to a previously working commit (one that was successfully deployed before), but the issue still occurs.
• I have confirmed that all required environment variables are correctly set up in both local and Vercel environments.
• The error appears to occur during the pre-rendering of a specific page (/support/terms-of-use).
- Error Details:
• The error log shows:
(node:638) [DEP0040] DeprecationWarning: The punycode
module is deprecated. Please use a userland alternative instead.
14:54:11.926
(Use node --trace-deprecation ...
to show where the warning was created)
14:54:11.969
(node:631) [DEP0040] DeprecationWarning: The punycode
module is deprecated. Please use a userland alternative instead.
14:54:11.970
(Use node --trace-deprecation ...
to show where the warning was created)
14:54:11.982
(node:645) [DEP0040] DeprecationWarning: The punycode
module is deprecated. Please use a userland alternative instead.
14:54:11.982
(Use node --trace-deprecation ...
to show where the warning was created)
14:54:15.684
Generating static pages (0/78) …
14:54:16.462
ReferenceError: document is not defined
14:54:16.462
at createTag (/vercel/path0/.next/server/chunks/8679.js:20:11481)
14:54:16.462
at /vercel/path0/.next/server/chunks/8679.js:20:24369
14:54:16.462
at /vercel/path0/.next/server/chunks/8679.js:20:24492
14:54:16.462
at /vercel/path0/.next/server/chunks/8679.js:20:27317
14:54:16.462
at /vercel/path0/.next/server/chunks/8679.js:20:11146
14:54:16.462
at 62970 (/vercel/path0/.next/server/chunks/8679.js:20:11150)
14:54:16.462
at t (/vercel/path0/.next/server/webpack-runtime.js:1:143)
14:54:16.462
at 13184 (/vercel/path0/.next/server/chunks/8679.js:20:2120)
14:54:16.462
at t (/vercel/path0/.next/server/webpack-runtime.js:1:143)
14:54:16.462
at 34322 (/vercel/path0/.next/server/chunks/6604.js:1:4040) {
14:54:16.462
digest: ‘1732007412’
Error occurred prerendering page “/support/terms-of-use”. Read more: Prerender Error with Next.js | Next.js
ReferenceError: document is not defined
at createTag (/vercel/path0/.next/server/chunks/5368.js:11:11326)
…
Generating static pages (58/78)
• The error suggests that the document object is being referenced during the server-side rendering phase, which is not allowed.
- Additional Steps Taken:
• I removed all third-party libraries and related code to rule out external dependencies as a cause, but the same issue persists.
• Verified that all environment variables are correct and match those used in the local environment.
• Reverted to an older commit that was previously successfully deployed to Vercel, but the error still occurs.
• Cleared the Vercel build cache and redeployed.
Reference:
Key Question:
Why is the deployment failing on Vercel despite working flawlessly in my local environment with the same configuration and codebase? Any insights or guidance would be greatly appreciated!