Nextjs 15 upgrade with React 19 function run time error

Hi,

I recently upgraded my project from Next.js 14 to 15. While I can run it without any issues locally — both in dev mode and serving a local production build — it works perfectly fine with no errors.

However, when I deploy it on Netlify, the function crashes and I get the following error in the logs. I’ve checked my code thoroughly and cannot find anywhere I might have missed adding "use client". Even the component contained in chunk 5059 is lazy-loaded.

At this point I’m running out of patience. I may need to test the same deployment on Vercel to see if the issue is specific to Netlify’s environment.

Could you please advise on what might be causing this difference in behavior between local and Netlify?

Thanks

Aug 8, 05:54:12 PM: 87621f83 ERROR Unhandled Promise Rejection {“errorType”:“Runtime.UnhandledPromiseRejection”,“errorMessage”:“ReferenceError: document is not defined”,“reason”:{“errorType”:“ReferenceError”,“errorMessage”:“document is not defined”,“stack”:[“ReferenceError: document is not defined”," at cW (/var/task/apps/kids-guitar-dojo/.next/server/chunks/5059.js:347:84907)“,” at iP.load (/var/task/apps/kids-guitar-dojo/.next/server/chunks/5059.js:382:133804)“,” at iS.load (/var/task/apps/kids-guitar-dojo/.next/server/chunks/5059.js:382:135966)“,” at /var/task/apps/kids-guitar-dojo/.next/server/chunks/1940.js:1:36488"," at Array.forEach ()“,” at 54674 (/var/task/apps/kids-guitar-dojo/.next/server/chunks/1940.js:1:36473)“,” at Function.c (/var/task/apps/kids-guitar-dojo/.next/server/webpack-runtime.js:1:143)“,” at process.processTicksAndRejections (node:internal/process/task_queues:95:5)“]},“promise”:{},“stack”:[“Runtime.UnhandledPromiseRejection: ReferenceError: document is not defined”,” at process. (file:///var/runtime/index.mjs:1326:17)“,” at process.emit (node:events:536:35)“,” at emitUnhandledRejection (node:internal/process/promises:250:13)“,” at throwUnhandledRejectionsMode (node:internal/process/promises:385:19)“,” at processPromiseRejections (node:internal/process/promises:470:17)“,” at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}

Hi @nolafs, I’ve routed this ticket to our helpdesk, we’ll follow up via email.

Thanks, it looks like the issue was related to Nx and Webpack. I was able to deploy after isolating the specific package that caused the crash. I excluded those packages from the server chunks in my Next.js config. From what I can tell, Nx tends to include many packages in the server barrel if they aren’t exported through a separate index.ts. I’ve now split some libs into index.ts and server.ts, with all client components in index.ts. These steps have resolved the issue for me.

Hi @nolafs, thanks for letting us know your issue is resolved.