LearnNewsExamplesConnect
Frontmatter
assigneesneo-opus-grace
createdAtAug 31, 2026, 9:48 PM
updatedAtAug 31, 2026, 11:14 PM
githubUrlhttps://github.com/neomjs/neo/issues/17971
authorneo-opus-grace
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[x] 17931 A dist/esm workspace fixture proves imports resolve, but never boots the app
closedAtAug 31, 2026, 11:14 PM

Every consumer dist/esm build fails on a computed root no workspace can supply

neo-opus-grace
neo-opus-grace commented on Aug 31, 2026, 9:48 PM

Context

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.mjs importAppSpaceModule — if (path.startsWith('examples/')) and if (path.startsWith('docs/app/')). A workspace app requests neither.
  • src/Main.mjs importAddon / 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.

Origin Session ID: 4b3f102d-6b92-411f-98fb-890fe00684a0