Skip to content

Fix Vercel ESM runtime error by removing "type": "module" from backend#1451

Closed
N2D4 wants to merge 2 commits into
devfrom
devin/1779302805-fix-esm-vercel
Closed

Fix Vercel ESM runtime error by removing "type": "module" from backend#1451
N2D4 wants to merge 2 commits into
devfrom
devin/1779302805-fix-esm-vercel

Conversation

@N2D4
Copy link
Copy Markdown
Contributor

@N2D4 N2D4 commented May 20, 2026

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, causing require is not defined in ES module scope at runtime.

The upstream fix (vercel/next.js#93612) is only in canary. Removing "type": "module" is safe since the backend has no .js source files and all configs use explicit extensions.

Link to Devin session: https://app.devin.ai/sessions/0df63fcdfcce4e87800bbb80ee0fde9e
Requested by: @N2D4

…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-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-auth-mcp Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-auth-skills Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-backend Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-dashboard Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-demo Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-docs Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-preview-backend Ready Ready Preview, Comment May 20, 2026 7:16pm
stack-preview-dashboard Ready Ready Preview, Comment May 20, 2026 7:16pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc0530c2-48c8-4bbd-9590-0cbab846780f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devin/1779302805-fix-esm-vercel

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant