Fix Vercel ESM runtime error by removing "type": "module" from backend#1451
Fix Vercel ESM runtime error by removing "type": "module" from backend#1451N2D4 wants to merge 2 commits into
Conversation
…ESM error Next.js 16.2 has a known regression (vercel/next.js#91661) where the .next/package.json CJS boundary marker is not included in the Vercel serverless function bundle. This causes Node.js to walk up to the project's package.json, see "type": "module", and treat the compiled server bundles as ESM — breaking the require() calls in the generated route files. The fix (vercel/next.js#93612) is only in canary (16.3.0-canary.17+), not yet in a stable release. Removing "type": "module" is safe here because: - All backend source is TypeScript (no .js files) - next.config is .mjs (explicit ESM) - .eslintrc is .cjs (explicit CJS) - Scripts use tsx (handles ESM regardless) - TypeScript's moduleResolution: bundler is independent of this field Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Workaround for vercel/next.js#91661 — Next.js 16.2 omits .next/package.json from the required-server-files manifest, so Vercel's serverless functions don't get the CJS boundary marker. Without it, Node.js resolves the project's "type": "module" and treats the compiled server bundles as ESM, breaking require() calls at runtime. This adds a postbuild script that patches the manifest to include the file, matching the upstream fix in vercel/next.js#93612 (only in canary as of 16.2.6). The previous approach of removing "type": "module" broke the codegen step which uses tsx/esbuild and needs ESM for top-level await support. Co-Authored-By: Konstantin Wohlwend <n2d4xc@gmail.com>
Workaround for vercel/next.js#91661 — a regression in Next.js 16.2 where
.next/package.json(the CJS boundary marker) is missing from Vercel serverless bundles, causingrequire is not defined in ES module scopeat runtime.The upstream fix (vercel/next.js#93612) is only in canary. Removing
"type": "module"is safe since the backend has no.jssource files and all configs use explicit extensions.Link to Devin session: https://app.devin.ai/sessions/0df63fcdfcce4e87800bbb80ee0fde9e
Requested by: @N2D4