Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
ERR_REQUIRE_ESM on Vercel runtime with "type": "module" monorepo — build succeeds, fails at runtime | GoodFirstPicks

ERR_REQUIRE_ESM on Vercel runtime with "type": "module" monorepo — build succeeds, fails at runtime

vercel/next.js 5 comments 11d ago
View on GitHub
highopenScope: somewhat clearSkill match: maybeNext.jsTypeScriptReact

Why this is a good first issue

The issue involves runtime-specific behavior in a monorepo setup with unclear root causes.

AI Summary

The issue occurs when deploying a Next.js 16.2.0 app with `"type": "module"` in a monorepo to Vercel, where the build succeeds but runtime fails with `ERR_REQUIRE_ESM`. The problem appears to be related to the `.next/package.json` boundary not being respected in Vercel's serverless functions, causing Node to fall back to the app's `"type": "module"`. The issue is intermittent in the test repo but consistent in larger monorepos, making it difficult to isolate and reproduce reliably.

Issue Description

Link to the code that reproduces this issue

https://github.com/ferc/next-16-2-esm-bug

To Reproduce

  1. Clone the repo and deploy to Vercel with root directory set to apps/web and build command cd ../.. && turbo run build --filter={apps/web}... && cd apps/web
  2. Visit the deployed URL (e.g. https://next-16-2-esm-bug.vercel.app/)
  3. The page returns 500 with ERR_REQUIRE_ESM

The repo is a pnpm monorepo with:

  • apps/web: Next.js 16.2.0 app with "type": "module" and turbopack.root set to monorepo root
  • packages/utils: workspace package with "type": "module" that re-exports a file using fs/promises and path
  • packages/storage, packages/ui, packages/ai-service: workspace packages with "type": "module" and dependencies (sentry, drizzle-orm, zod, tanstack, etc.)
  • Two dynamic pages (/ and /login) importing from workspace packages

Current vs. Expected behavior

Current: The build compiles successfully on Vercel, but dynamic pages fail at runtime with:

ERR_REQUIRE_ESM: require() of ES Module .next/server/app/page.js
from ___next_launcher.cjs not supported.
page.js is treated as an ES module file as it is a .js file whose nearest parent
package.json contains "type": "module"

next build generates .next/package.json with {"type": "commonjs"} which should override the parent's "type": "module". The error indicates this file is either missing or not found in the serverless function bundle at runtime.

Locally, next build + next start works fine — the issue only occurs when deployed to Vercel.

Expected: Pages should render correctly on Vercel, as they do locally.

Notes:

  • Works on 16.1.6, fails on 16.2.0
  • Build succeeds on Vercel — only fails at runtime in serverless functions
  • Works locally with next build + next start
  • The issue is intermittent on the test repo but consistent on a larger monorepo with the same setup

Provide environment information

Operating System:
  Platfor

GitHub Labels

linear: next

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 35 points when you complete it!

Risk Flags

  • runtime-specific
  • monorepo complexity
  • intermittent behavior
Loading labels...

Details

Points35 pts
Difficultyhigh
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno