-
Notifications
You must be signed in to change notification settings - Fork 30k
Labels
MiddlewareRelated to Next.js Middleware.Related to Next.js Middleware.TurbopackRelated to Turbopack with Next.js.Related to Turbopack with Next.js.
Description
Link to the code that reproduces this issue
https://github.com/mburumaxwell/dependabot-azure-devops/tree/main/apps/web
To Reproduce
- Create next 16 app
- Set `"type": "module"
- Add proxy.ts with some basic logic
- Deploy to vercel
- Make a request that
Current vs. Expected behavior
ESM-only should be supported on proxy/middleware too. Instead, I get the error this error from the application logs:
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/apps/web/.next/server/middleware.js from /var/task/apps/web/___next_launcher.cjs not supported.
middleware.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename middleware.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /var/task/apps/web/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at /opt/rust/nodejs.js:2:13527
at Function.Jr (/opt/rust/nodejs.js:2:13905)
at Ue.e.<computed>.Be._load (/opt/rust/nodejs.js:2:13497)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
code: 'ERR_REQUIRE_ESM'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/apps/web/.next/server/middleware.js from /var/task/apps/web/___next_launcher.cjs not supported.
middleware.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename middleware.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /var/task/apps/web/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at /opt/rust/nodejs.js:2:13527
at Function.Jr (/opt/rust/nodejs.js:2:13905)
at Ue.e.<computed>.Be._load (/opt/rust/nodejs.js:2:13497)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
code: 'ERR_REQUIRE_ESM'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 8
Binaries:
Node: 24.10.0
npm: 11.6.0
Yarn: N/A
pnpm: 10.13.1
Relevant Packages:
next: 16.0.3 // Latest available version is detected (16.0.3).
eslint-config-next: N/A
react: 19.2.0
react-dom: 19.2.0
typescript: 5.9.3
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
Turbopack, Middleware
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
No response
Metadata
Metadata
Assignees
Labels
MiddlewareRelated to Next.js Middleware.Related to Next.js Middleware.TurbopackRelated to Turbopack with Next.js.Related to Turbopack with Next.js.