You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Keep the rewrites when next.config.js is an ES module
copyNextjsConfig loads next.config.js with a require and only falls back to
import when that throws. The require returns a module namespace rather than
the config for an ES module in two cases: since Node.js 22.12 require of an
ES module succeeds and returns a namespace, and the nsm bin registers
esbuild-runner, which transpiles an ES module to CommonJS and marks the result
with __esModule.
Reading the config off the namespace left rewrites undefined, so it was
dropped from the generated .nsm/next.config.ts. A project that relies on a
rewrite to reach its routes then 404s on every request, with no error to
explain it.
Unwrap the default export whenever a namespace is loaded, whichever way it was
loaded. Resolve rewrites into a copy of the config, since a module namespace is
frozen, and pass a file URL to the import fallback so it also works on Windows.
Extract the loading into loadNextjsConfig and cover the CommonJS object,
CommonJS function and ES module configs with tests. The sample project used by
the existing tests has a CommonJS config, so the ES module path was untested.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V6bQ6zQqwT1vq9NkrG1UTm
0 commit comments