npm run build-dist-esm cannot succeed in any consuming workspace. It fails on a computed-root report for a directory the workspace has no reason to own, emitted for a code branch that cannot execute there.
Found while building the real-engine fixture for #17931 — the first thing that has ever run this build from outside this repository. Measured on dev @ f189cc6ffa, engine installed into a mkdtemp workspace, buildScripts/build/esmodules.mjs run for real. Full matrix: #17931 (comment 5483577069).
The Problem
#17921 added findUnresolvableImports, which refuses to let the build exit 0 while an emitted import does not resolve. It has three arms; the computed-root arm handles specifiers like `../../examples/${path.slice(9)}.mjs` — a template literal names no single file, so the arm resolves the literal prefix and asks whether that directory is in the output tree. Its stated purpose:
"The interpolation is never resolved — only the path before it. A whole source root is likely uncopied."
That inference holds inside this repository, where apps/, docs/, examples/ and src/ are all default source roots and all present. It does not hold for a consumer, where the same absence means the opposite: the directory is missing because the branch reading it is one this workspace never takes.
Measured residuals for a workspace with the engine installed and its deps hoisted, after clearing every blocker a consumer can clear:
dist/esm/src/Main.mjs → ../../../src/main/addon/${i.substring(3)}.mjs (directory src/main/addon/ is absent)
dist/esm/src/Main.mjs → ../../../src/main/addon/${e.substring(3)}.mjs (directory src/main/addon/ is absent)
dist/esm/src/worker/Data.mjs → ../../examples/${e.slice(9)}.mjs (directory dist/esm/examples/ is absent)
dist/esm/src/worker/Data.mjs → ../../docs/app/${e.slice(9)}.mjs (directory dist/esm/docs/app/ is absent)
Each traces to a guarded branch:
src/worker/Data.mjsimportAppSpaceModule — if (path.startsWith('examples/')) and if (path.startsWith('docs/app/')). A workspace app requests neither.
src/Main.mjsimportAddon / onDomContentLoaded — the if (addon.startsWith('WS/')) branch. A workspace declaring no WS/ addon never enters it.
examples/ is decisive on its own. For a consumer resolveSourceRoots returns ['apps', 'docs', 'node_modules/neo.mjs/src', 'src'] — examples is not among them, so dist/esm/examples/ cannot exist unless the workspace declares neo.esmSourceRoots: ['examples'], a root it has no reason to own and no documentation tells it to add. Every consumer build fails on that one line. The other three are conditional on workspace shape; this one is unconditional.
Confirmed by construction: adding neo.esmSourceRoots: ['examples'] plus a docs/ root and a src/main/addon/ directory is what finally took the build to exit 0 — four appeasements, none of which a real workspace would author.
The Architectural Reality
buildScripts/util/esmDistTransforms.mjs — findUnresolvableImports classifies missing / computed-root / engine-identity; computedSpecifierRoot truncates at the first interpolation.
buildScripts/build/esmodules.mjs — reports the three classes separately, then if (unresolvable.length > 0) process.exit(1) treats all three as equally fatal.
resolveSourceRoots in the same module owns the consumer default set that makes examples/ unreachable.
The missing arm is unaffected and remains the load-bearing one: a literal specifier that does not resolve is a real dangling import regardless of who is building, and it is what catches an uncopied root for any module actually imported statically.
The Fix
The build must stop treating computed-root as fatal, keeping it as a diagnostic. A computed specifier names no module; the arm cannot distinguish an uncopied source root from a branch this workspace does not take, and one of those two readings is wrong on every consumer build while the other has never once fired here on a real defect.
Concretely: exclude computed-root from the exit-1 set in buildScripts/build/esmodules.mjs, keep its console.error block, and reword it as a warning that names both readings instead of asserting the uncopied-root one.
The alternative — teaching the arm which computed roots are conditional — is rejected under Avoided Traps below.
Decision Record impact
none. This narrows a guard introduced by #17921; no ADR governs the dist/esm resolution guard.
Acceptance Criteria
A workspace with the engine installed, its deps hoisted, no examples/ and no src/main/addon/, and no neo.esmSourceRoots declaration, builds dist/esm to exit 0.
The computed-root report still prints, naming each specifier and its truncated root, and states both readings rather than asserting the uncopied-root one.
The missing arm still fails the build: a literal specifier that does not resolve exits 1, proven by a mutation that re-introduces one.
The engine-identity arm still fails the build, proven the same way.
The existing arms in test/playwright/unit/buildScripts/esmWorkspaceBuild.spec.mjs that assert exit 1 on an undeclared source root keep passing. Checked before filing rather than left as a risk: that case reports under do not resolve inside the output tree, i.e. the missing arm, so narrowing computed-root does not reach it.
Out of Scope
The WS/ addon path resolving outside dist/esm — a separate runtime defect, filed alongside this one.
The parse5 copy site, fixed under #17931.
Dependency resolution by filesystem path — #17868.
Any change to resolveSourceRoots' default set.
Avoided Traps
Adding examples to the consumer default roots. It would clear the decisive symptom and be wrong: a consumer has no examples/ tree, so the root would be copied as empty or skipped, and the other three reports would survive untouched.
Teaching the guard which computed roots are conditional — a list of "these branches are optional". That list is a second copy of control flow already expressed in Data.mjs and Main.mjs, and it goes stale the first time either grows a branch. The guard would then be confidently wrong instead of noisily right.
Leaving it and documenting the workaround. Four appeasement steps stand between a generated workspace and a working dist/esm build, none discoverable from the error text. A build every consumer must be told how to trick is not a guard.
Related
#17921 — introduced the guard.
#17931 — the real-engine fixture that surfaced this; carries the full measurement matrix.
#17868 — dependency resolution by filesystem path, the other blocker in the same measurement.
.github/workflows/consumer-runtime-build.yml — the sibling guard that builds from outside for the webpack targets, and the reason this class is known.
Handoff Retrieval Hints
Retrieval Hint: dist/esm computed-root guard consumer workspace examples source root
Reproducer: install the engine into a mkdtemp workspace, write only apps/<name>/ and a package.json with no neo key, run node <engine>/buildScripts/build/esmodules.mjs with the workspace as cwd.
Context
npm run build-dist-esmcannot succeed in any consuming workspace. It fails on acomputed-rootreport for a directory the workspace has no reason to own, emitted for a code branch that cannot execute there.Found while building the real-engine fixture for #17931 — the first thing that has ever run this build from outside this repository. Measured on
dev @ f189cc6ffa, engine installed into amkdtempworkspace,buildScripts/build/esmodules.mjsrun for real. Full matrix: #17931 (comment5483577069).The Problem
#17921 added
findUnresolvableImports, which refuses to let the build exit 0 while an emitted import does not resolve. It has three arms; thecomputed-rootarm handles specifiers like`../../examples/${path.slice(9)}.mjs`— a template literal names no single file, so the arm resolves the literal prefix and asks whether that directory is in the output tree. Its stated purpose:That inference holds inside this repository, where
apps/,docs/,examples/andsrc/are all default source roots and all present. It does not hold for a consumer, where the same absence means the opposite: the directory is missing because the branch reading it is one this workspace never takes.Measured residuals for a workspace with the engine installed and its deps hoisted, after clearing every blocker a consumer can clear:
dist/esm/src/Main.mjs → ../../../src/main/addon/${i.substring(3)}.mjs (directory src/main/addon/ is absent) dist/esm/src/Main.mjs → ../../../src/main/addon/${e.substring(3)}.mjs (directory src/main/addon/ is absent) dist/esm/src/worker/Data.mjs → ../../examples/${e.slice(9)}.mjs (directory dist/esm/examples/ is absent) dist/esm/src/worker/Data.mjs → ../../docs/app/${e.slice(9)}.mjs (directory dist/esm/docs/app/ is absent)Each traces to a guarded branch:
src/worker/Data.mjsimportAppSpaceModule—if (path.startsWith('examples/'))andif (path.startsWith('docs/app/')). A workspace app requests neither.src/Main.mjsimportAddon/onDomContentLoaded— theif (addon.startsWith('WS/'))branch. A workspace declaring noWS/addon never enters it.examples/is decisive on its own. For a consumerresolveSourceRootsreturns['apps', 'docs', 'node_modules/neo.mjs/src', 'src']—examplesis not among them, sodist/esm/examples/cannot exist unless the workspace declaresneo.esmSourceRoots: ['examples'], a root it has no reason to own and no documentation tells it to add. Every consumer build fails on that one line. The other three are conditional on workspace shape; this one is unconditional.Confirmed by construction: adding
neo.esmSourceRoots: ['examples']plus adocs/root and asrc/main/addon/directory is what finally took the build to exit 0 — four appeasements, none of which a real workspace would author.The Architectural Reality
buildScripts/util/esmDistTransforms.mjs—findUnresolvableImportsclassifiesmissing/computed-root/engine-identity;computedSpecifierRoottruncates at the first interpolation.buildScripts/build/esmodules.mjs— reports the three classes separately, thenif (unresolvable.length > 0) process.exit(1)treats all three as equally fatal.resolveSourceRootsin the same module owns the consumer default set that makesexamples/unreachable.The
missingarm is unaffected and remains the load-bearing one: a literal specifier that does not resolve is a real dangling import regardless of who is building, and it is what catches an uncopied root for any module actually imported statically.The Fix
The build must stop treating
computed-rootas fatal, keeping it as a diagnostic. A computed specifier names no module; the arm cannot distinguish an uncopied source root from a branch this workspace does not take, and one of those two readings is wrong on every consumer build while the other has never once fired here on a real defect.Concretely: exclude
computed-rootfrom the exit-1 set inbuildScripts/build/esmodules.mjs, keep itsconsole.errorblock, and reword it as a warning that names both readings instead of asserting the uncopied-root one.The alternative — teaching the arm which computed roots are conditional — is rejected under Avoided Traps below.
Decision Record impact
none. This narrows a guard introduced by #17921; no ADR governs thedist/esmresolution guard.Acceptance Criteria
examples/and nosrc/main/addon/, and noneo.esmSourceRootsdeclaration, buildsdist/esmto exit 0.computed-rootreport still prints, naming each specifier and its truncated root, and states both readings rather than asserting the uncopied-root one.missingarm still fails the build: a literal specifier that does not resolve exits 1, proven by a mutation that re-introduces one.engine-identityarm still fails the build, proven the same way.test/playwright/unit/buildScripts/esmWorkspaceBuild.spec.mjsthat assert exit 1 on an undeclared source root keep passing. Checked before filing rather than left as a risk: that case reports underdo not resolve inside the output tree, i.e. themissingarm, so narrowingcomputed-rootdoes not reach it.Out of Scope
WS/addon path resolving outsidedist/esm— a separate runtime defect, filed alongside this one.resolveSourceRoots' default set.Avoided Traps
Adding
examplesto the consumer default roots. It would clear the decisive symptom and be wrong: a consumer has noexamples/tree, so the root would be copied as empty or skipped, and the other three reports would survive untouched.Teaching the guard which computed roots are conditional — a list of "these branches are optional". That list is a second copy of control flow already expressed in
Data.mjsandMain.mjs, and it goes stale the first time either grows a branch. The guard would then be confidently wrong instead of noisily right.Leaving it and documenting the workaround. Four appeasement steps stand between a generated workspace and a working
dist/esmbuild, none discoverable from the error text. A build every consumer must be told how to trick is not a guard.Related
.github/workflows/consumer-runtime-build.yml— the sibling guard that builds from outside for the webpack targets, and the reason this class is known.Handoff Retrieval Hints
Retrieval Hint:
dist/esm computed-root guard consumer workspace examples source rootReproducer: install the engine into amkdtempworkspace, write onlyapps/<name>/and apackage.jsonwith noneokey, runnode <engine>/buildScripts/build/esmodules.mjswith the workspace as cwd.Origin Session ID: 4b3f102d-6b92-411f-98fb-890fe00684a0