Preview Error: this function has crashed (All deploy steps are success)

Hello Netlify Community and Support,

I am deploying a Next.js application which is part of a Yarn monorepo to Netlify. The build and deploy steps are reported as successful in the Netlify dashboard, but when I try to open the deployed site URL, I receive an error.

Upon checking the function logs, I see the following error repeatedly:

May 5, 07:54:21 PM: ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Cannot find module 'next/dist/server/lib/start-server.js'\nRequire stack:\n- /var/task/.netlify/dist/run/next.cjs", ...}

(This is the exact error message from my logs, timestamps may vary).

This indicates that a required Next.js server module is not being found when the serverless function is invoked at runtime.

My site URL: https://vedvaani.netlify.app/

Next.js project all deploy steps success, but when open preview site, it gives error.

Function log has error:
May 5, 09:46:43 PM: ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Cannot find module 'next/dist/server/lib/start-server.js'\nRequire stack:\n- /var/task/.netlify/dist/run/next.cjs","reason":{"errorType":"Error","errorMessage":"Cannot find module 'next/dist/server/lib/start-server.js'\nRequire stack:\n- /var/task/.netlify/dist/run/next.cjs","code":"MODULE_NOT_FOUND","requireStack":["/var/task/.netlify/dist/run/next.cjs"],"stack":["Error: Cannot find module 'next/dist/server/lib/start-server.js'","Require stack:","- /var/task/.netlify/dist/run/next.cjs"," at Function._resolveFilename (node:internal/modules/cjs/loader:1225:15)"," at Function._load (node:internal/modules/cjs/loader:1055:27)"," at TracingChannel.traceSync (node:diagnostics_channel:322:14)"," at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)"," at Module.require (node:internal/modules/cjs/loader:1311:12)"," at require (node:internal/modules/helpers:136:16)"," at Object.<anonymous> (/var/task/.netlify/dist/run/next.cjs:498:30)"," at Module._compile (node:internal/modules/cjs/loader:1554:14)"," at Object..js (node:internal/modules/cjs/loader:1706:10)"," at Module.load (node:internal/modules/cjs/loader:1289:32)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Cannot find module 'next/dist/server/lib/start-server.js'","Require stack:","- /var/task/.netlify/dist/run/next.cjs"," at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:518:28)"," at emitUnhandledRejection (node:internal/process/promises:252:13)"," at throwUnhandledRejectionsMode (node:internal/process/promises:388:19)"," at processPromiseRejections (node:internal/process/promises:475:17)"," at process.processTicksAndRejections (node:internal/process/task_queues:106:32)"]}

Build Settings:
Runtime: Next.js
Base directory: /
Package directory: apps/web-app
Build command: yarn workspace web-app build
Publish directory: apps/web-app/.next
Functions directory: netlify/functions
Build status: Active

Error screenshot:

Deploy shows success:

Function logs:

So, not just me. I think this is a straight compatibility issue…

After trying a LOT of options, I gave up and created a new repo and deployed the subtree of my main repo to it using git subtree, and that worked. Problem solved.

Thanks Daniel for sharing, is git subtree a temporary workaround?

It would be really helpful if you can share in detail or steps to solve it.

If anyone have a more simple solution, kindly share.

Thanks

@jaydeep-vv, do you have a minimal reproduction to share?