Hi everyone,
I’m having trouble deploying my Next.js 16 project on Netlify. The build completes successfully, but the deploy fails during the Edge Functions bundling step.
Netlify site name
What I’m deploying
-
Next.js 16.0.3 (Turbopack)
-
App Router
-
NextAuth
-
pnpm
-
Using the official
@netlify/plugin-nextjs
Problem
The build succeeds, but Netlify fails when bundling the internal Edge function generated by the Next.js runtime:
Failed during stage 'building site': Build script returned non-zero exit code: 2
Error: Failed to compile CJS module:
.netlify/edge-functions/.../middleware.js
Caused by Error: Failed to load external module pino
Error: Failed to compile CJS module: node_modules/pino/pino.js
It looks like Netlify’s Edge Runtime is trying to load pino (a CJS package), which is not compatible with Edge Functions.
Build log (full excerpt)
(Pasting the key part only for readability — happy to provide the full logs if needed)
12:53:55 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:53:55 PM: Error: Failed to compile CJS module:
/opt/build/repo/.netlify/edge-functions/.../middleware.js
Caused by Error: Failed to load external module pino
Error: Failed to compile CJS module: node_modules/pino/pino.js
What I suspect
-
It might be caused by NextAuth or middleware pulling in a dependency (like
pino) that isn’t edge-compatible. -
The internal “___netlify-edge-handler-node-middleware” function tries to bundle it anyway.
My questions
-
Is there a way to disable Edge Middleware handling in the Netlify Next.js runtime?
(i.e. force everything to run as regular server functions, not edge) -
What are the recommended build settings for NextJS v16?
Build command: pnpm build
Publish directory: .next