Context
A physical installed-consumer probe at Engine dev@f1d3ed2840 exposed a Main-bundle failure before the path-contract fixture could run. The consumer was generated from Neo’s minimal app scaffold, installed Neo beneath node_modules/neo.mjs, and intentionally had no workspace src/main/addon/ directory.
Both Main builds fail:
ERROR in node_modules/neo.mjs/src/Main.mjs
Module not found: Error: Can't resolve '../../../src/main/addon'
Creating an empty consumer src/main/addon/ directory—without changing source or config—makes both development and production Main bundles compile. This positive control isolates directory existence as the failing axis.
This is unfinished historical work, not a new concept. #3157 introduced opt-in WS/* workspace addons. #3341 then reported that Main bundling breaks when Webpack parses a workspace directory that does not exist; commit 3e7fb65 introduced the current ContextReplacementPlugin callback and the ticket closed. The current callback repaired the inside-Engine mapping but left the absent installed-consumer arm unresolved.
The Problem
WS/* is optional by contract. learn/guides/fundamentals/MainThreadAddons.md says the prefix tells Main to load from the workspace src/main/addon directory; an app that configures no WS/* addon should not need to create that directory.
Webpack nevertheless resolves every dynamic-context root during compilation. src/Main.mjs carries two distinct contexts:
- package-owned
./main/addon/** for Engine addons;
- workspace-owned
../../../src/main/addon/** for WS/* addons.
Both Main configs rewrite the workspace request only when insideNeo === true. In an installed consumer they correctly leave the request pointing at the workspace—but if the optional directory is absent, Webpack fails before it can prove that no WS/* addon was requested.
The minimal scaffold does not create src/main/addon/, so a generated zero-custom-addon consumer cannot build Main without a manual empty-directory workaround.
The Architectural Reality
src/Main.mjs:351-355,413-418 owns package-vs-workspace addon identity.
learn/guides/fundamentals/MainThreadAddons.md:279-283 owns the opt-in WS/* contract.
buildScripts/webpack/development/webpack.config.main.mjs:60-67 and production :59-66 duplicate the current context mapping.
buildScripts/webpack/workerContextRebasePlugin.mjs is the direct precedent for optional external roots: resolve a real consumer root when present; otherwise use a resolvable package root with a matches-nothing context so framework files cannot leak into the consumer namespace.
- The Main case needs a sibling helper rather than reusing the worker helper: Main rewrites in-repo, preserves a present external workspace root, and empties only an absent external root; the worker helper is an external app-space rebaser and an in-repo no-op.
The Fix
- Add shared
buildScripts/webpack/mainAddonContextPlugin.mjs, sibling to workerContextRebasePlugin.mjs, and use it from both Main configs.
- Handle only the
../../../src/main/addon context during the unresolved phase (context.resource === undefined):
- inside Engine: preserve today’s rewrite to package
./main/addon;
- installed consumer + workspace root present: preserve the authored workspace request;
- installed consumer + root absent: point at the package’s resolvable
./main/addon root and set regExp = /(?!)/, emitting no WS/* modules.
- Extend the physical packaged-consumer build guard (or its coherently renamed successor) to compile Main in both modes with the optional root absent and present.
Pre-Flight (structural fast-path): buildScripts/webpack/mainAddonContextPlugin.mjs matches sibling workerContextRebasePlugin.mjs; both are shared Webpack context-ownership helpers consumed by development/production configs. No novel directory or architecture-map change.
Contract Ledger Matrix
| Target Surface |
Source of Authority |
Proposed Behavior |
Fallback |
Docs |
Evidence |
WS/* Main addon context |
Main.mjs; Main Thread Addons guide |
consumer src/main/addon is optional; present modules stay loadable |
absent root becomes an empty context, never package-addon leakage |
existing guide remains authoritative |
physical dev/prod consumer builds |
| development/production Main Webpack configs |
shared mainAddonContextPlugin.mjs |
byte-identical context semantics across modes |
fail build on any non-optional resolution error |
helper JSDoc |
exact config imports + both compiles |
| consumer-build guard |
packaged minimal app |
exercise absent and present workspace-addon roots through real Webpack |
no simulated-layout substitute |
guard JSDoc |
positive module-graph arm + two mutations |
Decision Record impact
none — completes the existing #3157/#3341 workspace-addon contract; no public API or architectural direction changes.
Acceptance Criteria
Out of Scope
- Creating empty directories in app scaffolds as a workaround.
- Changing
WS/* runtime/config syntax or Main addon lifecycle.
- Data/Canvas/Task worker context reach (owned separately by #17881 and D#1881).
- The URL-root/ESM generator contract in #17884 / D#17886.
Avoided Traps
- Scaffold an empty directory: hides the build contract and fails for existing consumers.
- Fallback to package addons without an empty regex: silently exposes Engine addons as workspace addons.
- Path-arithmetic-only test: PR #17882’s simulated control missed absent optional roots; the physical npm layout is the required instrument.
- Patch one environment: the development/production callbacks are currently identical and must stay governed by one helper.
Related
Related: #3157, #3341, #9584, #17881, PR #17882, D#17886.
Live latest-open sweep: checked the latest 20 open issues at 2026-08-31T02:39:05.603Z; no equivalent found. Recent 30-message all-read-state A2A claim sweep found no overlapping Main-addon lane. Knowledge Base returned the Main Thread Addons guide and Main source but no equivalent current ticket.
Origin Session ID: a63227a3-7e65-4384-ba2c-89a2fb98ec7b
Retrieval Hint: "external consumer Main webpack missing optional src/main/addon WS ContextReplacementPlugin #3341"
Context
A physical installed-consumer probe at Engine
dev@f1d3ed2840exposed a Main-bundle failure before the path-contract fixture could run. The consumer was generated from Neo’s minimal app scaffold, installed Neo beneathnode_modules/neo.mjs, and intentionally had no workspacesrc/main/addon/directory.Both Main builds fail:
Creating an empty consumer
src/main/addon/directory—without changing source or config—makes both development and production Main bundles compile. This positive control isolates directory existence as the failing axis.This is unfinished historical work, not a new concept. #3157 introduced opt-in
WS/*workspace addons. #3341 then reported that Main bundling breaks when Webpack parses a workspace directory that does not exist; commit3e7fb65introduced the currentContextReplacementPlugincallback and the ticket closed. The current callback repaired the inside-Engine mapping but left the absent installed-consumer arm unresolved.The Problem
WS/*is optional by contract.learn/guides/fundamentals/MainThreadAddons.mdsays the prefix tells Main to load from the workspacesrc/main/addondirectory; an app that configures noWS/*addon should not need to create that directory.Webpack nevertheless resolves every dynamic-context root during compilation.
src/Main.mjscarries two distinct contexts:./main/addon/**for Engine addons;../../../src/main/addon/**forWS/*addons.Both Main configs rewrite the workspace request only when
insideNeo === true. In an installed consumer they correctly leave the request pointing at the workspace—but if the optional directory is absent, Webpack fails before it can prove that noWS/*addon was requested.The minimal scaffold does not create
src/main/addon/, so a generated zero-custom-addon consumer cannot build Main without a manual empty-directory workaround.The Architectural Reality
src/Main.mjs:351-355,413-418owns package-vs-workspace addon identity.learn/guides/fundamentals/MainThreadAddons.md:279-283owns the opt-inWS/*contract.buildScripts/webpack/development/webpack.config.main.mjs:60-67and production:59-66duplicate the current context mapping.buildScripts/webpack/workerContextRebasePlugin.mjsis the direct precedent for optional external roots: resolve a real consumer root when present; otherwise use a resolvable package root with a matches-nothing context so framework files cannot leak into the consumer namespace.The Fix
buildScripts/webpack/mainAddonContextPlugin.mjs, sibling toworkerContextRebasePlugin.mjs, and use it from both Main configs.../../../src/main/addoncontext during the unresolved phase (context.resource === undefined):./main/addon;./main/addonroot and setregExp = /(?!)/, emitting noWS/*modules.Pre-Flight (structural fast-path):
buildScripts/webpack/mainAddonContextPlugin.mjsmatches siblingworkerContextRebasePlugin.mjs; both are shared Webpack context-ownership helpers consumed by development/production configs. No novel directory or architecture-map change.Contract Ledger Matrix
WS/*Main addon contextMain.mjs; Main Thread Addons guidesrc/main/addonis optional; present modules stay loadablemainAddonContextPlugin.mjsDecision Record impact
none— completes the existing #3157/#3341 workspace-addon contract; no public API or architectural direction changes.Acceptance Criteria
src/main/addon/compiles development and production Main bundles with zero resolution errors.src/main/addon/**does not leak into theWS/*namespace.src/main/addon/ConsumerMainAddon.mjs; both builds include it in the module graph.Can't resolve '../../../src/main/addon'in both modes.ConsumerMainAddon.mjsdisappear, so the positive arm fails non-vacuously.Out of Scope
WS/*runtime/config syntax or Main addon lifecycle.Avoided Traps
Related
Related: #3157, #3341, #9584, #17881, PR #17882, D#17886.
Live latest-open sweep: checked the latest 20 open issues at 2026-08-31T02:39:05.603Z; no equivalent found. Recent 30-message all-read-state A2A claim sweep found no overlapping Main-addon lane. Knowledge Base returned the Main Thread Addons guide and Main source but no equivalent current ticket.
Origin Session ID: a63227a3-7e65-4384-ba2c-89a2fb98ec7b
Retrieval Hint: "external consumer Main webpack missing optional src/main/addon WS ContextReplacementPlugin #3341"