Skip to content

Node.js middleware does not work with webpack builds #3171

@cshawaus

Description

@cshawaus

While attempting some build testing between Turbopack and Webpack, I noticed that Node.js middleware produces a CJS error and crashes the Edge Function. This is all I got in the logs, but tracing may provide more information.

Oct 10, 01:16:03 AM: error  Error: Failed to compile CJS module: /root/.netlify/edge-functions/___netlify-edge-handler-node-middleware/server/.next/server/middleware.js
Oct 10, 01:16:03 AM: error      at seedCJSModuleCacheAndReturnTarget (file:///root/.netlify/edge-functions/___netlify-edge-handler-node-middleware/edge-runtime/lib/cjs.ts:230:11)
Oct 10, 01:16:03 AM: error      at Module._resolveFilename (file:///root/.netlify/edge-functions/___netlify-edge-handler-node-middleware/edge-runtime/lib/cjs.ts:322:16)
Oct 10, 01:16:03 AM: error      at Module._load (node:module:497:27)
Oct 10, 01:16:03 AM: error      at Module.require (node:module:681:19)
Oct 10, 01:16:03 AM: error      at require (node:module:816:16)
Oct 10, 01:16:03 AM: error      at file:///root/.netlify/edge-functions/___netlify-edge-handler-node-middleware/server/node-middleware.js:1551:24

With Next.js 16 moving to Turbopack by default, this doesn't feel like a high priority, but it's worth a mention in case anyone else is running up against it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions