Skip to content

Traced file set depends on the Node version running the trace (module-sync gated on build-time Node >= 22) #603

Description

@timfish

Whether a package's module-sync export target is traced depends on the Node.js
version running nodeFileTrace (getNodeMajorVersion() >= 22 in
resolve-dependency.ts), not on what supported runtimes resolve. Node's CJS loader
matches module-sync from 20.19, so every Node 20.x build (including latest
20.20.2) omits a file that even its own runtime resolves — pruned output crashes
with MODULE_NOT_FOUND with no build/deploy version skew at all.

Minimal repro: https://github.com/timfish/repro-nft-module-syncnpm run repro
fails on Node 20.x, passes on Node 22; require.resolve('meriyah') and the trace
disagree within a single process.

Related: the wildcard-exports branch from #584 has the mirror problem — on Node >= 22
it emits only the module-sync target (fallback gated on moduleSyncCatchall,
default false), breaking older deploy runtimes.

Possible directions — happy to PR whichever you prefer:

  1. Default moduleSyncCatchall to true (feat: add module-sync catchall tracing #584 already emits both targets behind it)
  2. Drop the version gates and always dual-emit
  3. Correct the version check (>= 22 → also 20.19+) — still leaves build-vs-deploy
    version skew unsound

Seen in the wild via meriyah@6.1.x: Nitro server bundles (nuxt/solidstart/tanstack
prod servers crash at boot) and AWS Lambda layers built on Node 20.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions