Traced externals: `module-sync` export target pruned from `.output/server/node_modules` when building on Node 20
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Environment
nitropack 2.13.4 (resolving @vercel/nft 1.10.2), meriyah 6.1.4.
Node v20.19.5 and v20.20.2 (latest 20.x): broken. Node v22.19.0: works.
Default nitro config — no externals customization.
Reproduction
https://github.com/timfish/repro-nitro-module-sync-trace
npm install && npx nitropack build (Node 20.x), then
ls .output/server/node_modules/meriyah/dist/ → meriyah.cjs only;
node .output/server/index.mjs + curl localhost:3000/ → 500.
Describe the bug
Building on Node 20.x copies a traced external dependency incompletely:
meriyah/ lands in .output/server/node_modules with its require-condition file,
but the file its module-sync condition points at is missing. The built server then
throws Cannot find module '…/meriyah/dist/meriyah.mjs' — on the same Node that ran
the build (the CJS loader matches module-sync from 20.19). Building on Node 22
produces working output.
Root cause is in @vercel/nft, which gates module-sync on the build-time Node
major: vercel/nft#603.
This is not #4456: there the requiring package is bundled and meriyah goes
missing entirely via the commonjs-proxy resolution loss; here tracing works and the
copy is merely incomplete. Fixing one doesn't fix the other (comparison table in the
repro README).
Verified workaround / possible Nitro-side fix independent of nft's decision:
externals: { traceOptions: { moduleSyncCatchall: true } } (nft ≥ 1.10 emits both
targets with it) — Nitro could pass this by default. Happy to PR that if preferred.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the linked reproduction and run npm install && npx nitropack build on Node 20, then inspect .output/server/node_modules/meriyah/dist/ and run .output/server/index.mjs. Start by tracing how externals.traceOptions reaches the NFT configuration. Done means the Node 20 build includes the module-sync target and the server responds successfully instead of throwing the missing meriyah.mjs error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100