LearnNewsExamplesConnect
Frontmatter
assigneesneo-opus-grace
createdAtNov 14, 2026, 8:15 PM
updatedAtNov 15, 2026, 12:57 AM
githubUrlhttps://github.com/neomjs/neo/issues/20964
authorneo-opus-grace
commentsCount0
parentIssue20667
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[x] 20863 Emitted ESM package classes can load a second Engine graph
blocking[]
closedAtNov 15, 2026, 12:57 AM

dist/esm: a package's Canvas module loads from outside the emitted tree

neo-opus-grace
neo-opus-grace commented on Nov 14, 2026, 8:15 PM

Context

My boundary review on #20863 (comment 6880574910) named this from reading the code, and promised an artifact probe. This is the probe: dev 3c9ef1039f's own transforms and identity guard, run over the real src/worker/Canvas.mjs in a workspace whose dist/esm exists:

emitted package branch:     `../../../${path.slice(13)}.mjs`   (unchanged by the transform)
loadModule({path: 'node_modules/widget/canvas/Renderer'}) requests: dist/widget/canvas/Renderer.mjs   (exists: false)
emitted package copy:       dist/esm/node_modules/widget/canvas/Renderer.mjs                         (exists: false)
findUnresolvableImports on that branch: no verdict

Positive control: in the same run, the guard reports the stub tree's absent siblings and computed-root ../canvas/${path.slice(11)}.mjs. The package branch's root resolves to dist/, which every dist/esm build has, so it passes.

The Problem

Canvas#loadModule's node_modules/ branch climbs three levels from the worker file. From an installed engine's node_modules/neo.mjs/src/worker/, that lands in node_modules/. From dist/esm/src/worker/, it lands in dist/, outside both trees. Main has a layout switch for the same request; the Canvas worker has none.

The build never emits neo.canvasModules roots either. So even a corrected path would find no emitted copy, and loading the source copy would bring the source Engine into the Canvas worker. Neither the build nor its identity guard reports any of this.

The Architectural Reality

  • src/worker/Canvas.mjs loadModule(): src/canvas/ → ../canvas/…; node_modules/ → ../../../${path.slice(13)}.mjs; anything else → ../../${path}.mjs.
  • src/Main.mjs importAddonModule(): the Main thread's switch for package addons. Inside an installed engine (import.meta.url holds /node_modules/neo.mjs/) it imports ../../${modulePath}.mjs, from any other tree ../node_modules/${modulePath}.mjs. Both specifiers stay literal, so webpack resolves each as a context of its own.
  • buildScripts/build/esmodules.mjs admits declared neo.mainAddons roots only. buildScripts/util/declaredPackageRoots.mjs reads neo.canvasModules too, but nothing in the ESM build consumes it.
  • findUnresolvableImports() passes a computed specifier whose root directory exists. dist/ always exists.
  • After #20956: createEsmBuildPlan() and esmDestination() own every admission's destination.
  • Design authority: n/a: the probe above shows a request for a file no build emits.

The Fix

  1. Give the Canvas worker's node_modules/ branch the layout switch Main uses: in dist/esm it resolves under the emitted tree's node_modules/.
  2. Emit declared neo.canvasModules roots through #20956's plan (esmDestination()), with their Engine edges rebased the way Main roots are.
  3. Fail the build for a computed specifier whose root leaves dist/esm, instead of passing it because the directory exists. An absent root inside the tree keeps its current warning. Retired at intake, below.

Decision Record impact: none.

Intake — 14 November 2026, after #20956 and #20973

Drift probe fired: buildScripts/build/esmodules.mjs, buildScripts/util/esmBuildGraph.mjs and buildScripts/util/esmDistTransforms.mjs changed (#20956's plan, #20973's Main helper check). The premise holds at dev d6e427e7a7: the Canvas branch still climbs ../../../, and the build still hands the plan mainAddonPackageRoots() only.

Prescription, sharpened:

  1. The emitted Canvas worker's package root follows Main's emitted one. rewriteEsmImports() already rewrites the emitted Main.mjs's computed package roots onto dist/esm/node_modules; it now rewrites Canvas.mjs's ../../../ root the same way. The source file needs no runtime switch: Main's exists for the engine repository's own layout, which installs no Canvas packages (canvasModuleContextPlugin). Webpack builds are untouched, and check-consumer-runtime-build.mjs's declared-canvas expectation stays their witness. Corrected during implementation: the first version of this intake named a runtime switch.
  2. The ESM build's declared roots become neo.mainAddons plus neo.canvasModules, each entry tagged with its manifest key. The plan copies both, rewriteEsmImports() rebases both onto the emitted Engine, and #20973's outside-root helper check covers Canvas roots too, naming the declaring key in its remedy.
  3. AC-3 is retired. A computed root that leaves dist/esm is exactly the dormant installed-layout branch that Main carries, and that the Canvas worker carries after fix 1. The identity guard cannot tell a switch's dormant branch from a live one, so failing such a root would fail every build. After fix 1, no live branch leaves the tree.

Prescription checked: src/worker/Canvas.mjs owns the runtime path; buildScripts/build/esmodules.mjs with buildScripts/util/esmBuildGraph.mjs own admission. Sophie owns the plan and Main admission (#20821, #20956); the fork is with her.

Contract Ledger

Target surface Source of authority Proposed behaviour Fallback / edge Docs Evidence
Neo.worker.Canvas#loadModule, node_modules/ paths (existing) rewriteEsmImports()' rewrite of the emitted Main roots In dist/esm, the emitted worker resolves a package under the emitted tree's node_modules/; source and webpack builds are unchanged Unknown paths fail as today rewriteEsmImports JSDoc Unit (real build: the emitted worker loads the emitted copy)
ESM build, neo.canvasModules roots (new admission) declaredPackageRoots.mjs Copied into dist/esm/node_modules/<package>/…, Engine edges rebased onto the emitted Engine, outside-root helpers checked as Main roots are An undeclared package stays unadmitted learn/guides/advanced/CanvasArchitecture.md Unit (real build, identity read)
ESM build's outside-root helper refusal (#20973) esmBuildGraph.mjs The remedy names the declaring key (neo.mainAddons or neo.canvasModules) — MainThreadAddons.md Unit

Acceptance Criteria

  • A workspace declaring neo.canvasModules builds to dist/esm. The emitted Canvas worker loads the package module from dist/esm/node_modules/<package>/…, and that module reaches the emitted CoreBase: an identity read, not a mount.
  • Source and webpack builds keep loading it from node_modules/<package>/….
  • A computed specifier whose root leaves dist/esm fails the build, naming the importer. An absent root inside dist/esm stays a warning. Retired at intake (see Intake, point 3).
  • An undeclared package stays unadmitted.

Out of Scope

Main addons (#20963); the App static graph (#20863); the runtime URL redesign (Discussion #17886).

Related

#20863 / #20956 (the plan this reuses) · #20778 (the runtime package paths, my seam) · #20963 (the Main-root twin) · #20821 · #20667 (parent)

Ownership: self-assigned (Grace, owner of #20778's runtime path). Blocked by #20863.

Live latest-open + closed sweep: checked latest 20 open (50 open, orange band) + closed search ("Canvas loadModule dist/esm package canvasModules": no hits) and open search ("canvasModules dist/esm", "Canvas dist/esm": #20863, #20963, both read) at 2026-11-14T19:15Z; A2A last 15 messages: no overlapping claim; Memory Core problem-noun search: only my own #20778 work; own assignments (#20952, #20911, #20884, #20790) do not overlap. No equivalent found.

Retrieval Hint: "dist/esm Canvas worker loadModule package path outside emitted tree canvasModules"

tobiu referenced in commit 6f1f8b2 - "feat(build): dist/esm emits declared Canvas module roots on its one Engine graph (#20964) (#20979) on Nov 15, 2026, 12:57 AM
tobiu closed this issue on Nov 15, 2026, 12:57 AM