Context
Found while reviewing #20956 (static package graphs for #20863). A package declares neo.mainAddons: ['main']. Its main/Addon.mjs re-exports ../outside/Helper.mjs, and that helper re-exports ../../neo.mjs/src/core/Base.mjs.
The ESM build exits 0 on dev (412a9c25d8) and on #20956's head (a678dbb220). The emitted addon imports the helper from its source location, so the Main thread loads the source CoreBase beside the emitted one.
Reproduction: a synthetic workspace with the stub engine that test/playwright/unit/buildScripts/esmWorkspaceBuild.spec.mjs uses, built with buildScripts/build/esmodules.mjs, then the emitted addon imported in Node. Both trees print the same:
status 0
dist/esm/node_modules/widget/main/Addon.mjs: export{default}from"../../../../../node_modules/widget/outside/Helper.mjs";
Addon.default.engineUrl: <workspace>/node_modules/neo.mjs/src/core/Base.mjsThe Problem
findUnresolvableImports() reads emitted specifiers. The addon's specifier names the package, not node_modules/neo.mjs, so the identity guard passes. The split happens one edge further, in a file the build never emits. Mounting still succeeds; DistEsmWorkspaceBoot.spec.mjs's split-graph arm shows why mount success is no oracle.
This is the Main-side twin of #20863: a source fallback that silently reintroduces the source Engine.
Admitting the helper is not the fix. #20821's Avoided Traps exclude "admitting sibling paths outside declared roots", and #20956 keeps that boundary (its spec: "Main-only roots do not discover their outside-root helpers").
The Architectural Reality
rewriteMainAddonImports() (buildScripts/util/esmDistTransforms.mjs): for a declared-root module, a target outside every declared root and outside the Engine keeps its source location (target = resolved).
- After #20956,
createEsmBuildPlan() (buildScripts/util/esmBuildGraph.mjs) walks the static edges of workspace modules only. Declared-root modules are copied, not walked, so their outside-root edges are never classified.
- Design authority:
rewriteMainAddonImports on dev: "Rebases declared Main-addon modules onto the emitted tree's single Engine graph." And enginePackagePath: "Every specifier that still names it after the rewrite addresses a SECOND engine module graph".
The Fix
- Classify the static edges of declared Main-root modules without admitting their targets. An edge that leaves every declared root and transitively reaches the Engine fails the build. The error names the importer, the specifier and the remedy: declare the helper's directory in
neo.mainAddons, or move it inside a declared root.
- An outside-root helper with no Engine edge keeps today's host fallback.
- Reuse #20956's plan and failure format; no second walker.
Decision Record impact: none.
Contract Ledger
Backfilled at review of PR #20973; the first version of this ticket had none.
| Target surface |
Source of authority |
Proposed behaviour |
Fallback / edge |
Docs |
Evidence |
| ESM build: a declared Main-root module's static edge (new check) |
This ticket; rewriteMainAddonImports design authority above |
An edge to a module the build does not emit, whose static graph reaches the Engine, fails the build naming the importer, the specifier and the remedy |
A helper with no Engine edge keeps its host path; dynamic import() is not inspected |
learn/guides/fundamentals/MainThreadAddons.md (packaging section) |
Unit: graph spec and real-build arms |
neo.mainAddons package-authoring rule (existing) |
MainThreadAddons.md |
Unchanged declaration; the rule that every Engine-reaching helper lives inside a declared root is now enforced by the build |
— |
Same guide: its "the ESM build does not inspect imports inside host dependencies" sentence changes with this ticket |
— |
Acceptance Criteria
Out of Scope
Admitting outside-root files; runtime loadModule and Canvas admission (#20778); the App-graph package closure (#20863).
Related
#20863 / #20956 (App-side twin; this builds on its plan) · #20821 (Main-addon admission) · #20667 (parent) · #17972 (an earlier Main-thread second-Engine defect) · #17921 (the identity guard)
unowned-rationale: blocked until #20863's plan lands. Sophie owns the Main-addon admission (#20821) and the plan (#20956); offered to her in the #20956 review.
Live latest-open + closed sweep: checked latest 20 open (50 open, orange band) + closed search ("Main addon root dist/esm Engine helper"; #20821 and #17972 read, Out of Scope / Avoided Traps) at 2026-11-14T18:54Z; A2A last 30 messages: no overlapping claim; Memory Core problem-noun search: no prior rationale; own assignments (#20952, #20911, #20884, #20790) do not overlap. No equivalent found.
Retrieval Hint: "dist/esm Main addon declared root outside helper source Engine split"
Context
Found while reviewing #20956 (static package graphs for #20863). A package declares
neo.mainAddons: ['main']. Itsmain/Addon.mjsre-exports../outside/Helper.mjs, and that helper re-exports../../neo.mjs/src/core/Base.mjs.The ESM build exits 0 on
dev(412a9c25d8) and on #20956's head (a678dbb220). The emitted addon imports the helper from its source location, so the Main thread loads the source CoreBase beside the emitted one.Reproduction: a synthetic workspace with the stub engine that
test/playwright/unit/buildScripts/esmWorkspaceBuild.spec.mjsuses, built withbuildScripts/build/esmodules.mjs, then the emitted addon imported in Node. Both trees print the same:status 0 dist/esm/node_modules/widget/main/Addon.mjs: export{default}from"../../../../../node_modules/widget/outside/Helper.mjs"; Addon.default.engineUrl: <workspace>/node_modules/neo.mjs/src/core/Base.mjsThe Problem
findUnresolvableImports()reads emitted specifiers. The addon's specifier names the package, notnode_modules/neo.mjs, so the identity guard passes. The split happens one edge further, in a file the build never emits. Mounting still succeeds;DistEsmWorkspaceBoot.spec.mjs's split-graph arm shows why mount success is no oracle.This is the Main-side twin of #20863: a source fallback that silently reintroduces the source Engine.
Admitting the helper is not the fix. #20821's Avoided Traps exclude "admitting sibling paths outside declared roots", and #20956 keeps that boundary (its spec: "Main-only roots do not discover their outside-root helpers").
The Architectural Reality
rewriteMainAddonImports()(buildScripts/util/esmDistTransforms.mjs): for a declared-root module, a target outside every declared root and outside the Engine keeps its source location (target = resolved).createEsmBuildPlan()(buildScripts/util/esmBuildGraph.mjs) walks the static edges of workspace modules only. Declared-root modules are copied, not walked, so their outside-root edges are never classified.rewriteMainAddonImportsondev: "Rebases declared Main-addon modules onto the emitted tree's single Engine graph." AndenginePackagePath: "Every specifier that still names it after the rewrite addresses a SECOND engine module graph".The Fix
neo.mainAddons, or move it inside a declared root.Decision Record impact: none.
Contract Ledger
Backfilled at review of PR #20973; the first version of this ticket had none.
rewriteMainAddonImportsdesign authority aboveimport()is not inspectedlearn/guides/fundamentals/MainThreadAddons.md(packaging section)neo.mainAddonspackage-authoring rule (existing)MainThreadAddons.mdAcceptance Criteria
esmDistTransforms.spec.mjsand the Main-addon lifecycle arms ofDistEsmWorkspaceBoot.spec.mjs.Out of Scope
Admitting outside-root files; runtime
loadModuleand Canvas admission (#20778); the App-graph package closure (#20863).Related
#20863 / #20956 (App-side twin; this builds on its plan) · #20821 (Main-addon admission) · #20667 (parent) · #17972 (an earlier Main-thread second-Engine defect) · #17921 (the identity guard)
unowned-rationale: blocked until #20863's plan lands. Sophie owns the Main-addon admission (#20821) and the plan (#20956); offered to her in the #20956 review.
Live latest-open + closed sweep: checked latest 20 open (50 open, orange band) + closed search ("Main addon root dist/esm Engine helper"; #20821 and #17972 read, Out of Scope / Avoided Traps) at 2026-11-14T18:54Z; A2A last 30 messages: no overlapping claim; Memory Core problem-noun search: no prior rationale; own assignments (#20952, #20911, #20884, #20790) do not overlap. No equivalent found.
Retrieval Hint: "dist/esm Main addon declared root outside helper source Engine split"