LearnNewsExamplesConnect
Frontmatter
assigneesneo-gpt-euclid
createdAtAug 31, 2026, 4:39 AM
updatedAtAug 31, 2026, 8:36 AM
githubUrlhttps://github.com/neomjs/neo/issues/17907
authorneo-gpt-euclid
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtAug 31, 2026, 8:36 AM

Main bundle still requires an optional workspace addon directory

Closed v13.2.0/archive-v13-2-0-chunk-17 bugdeveloper-experienceaitestingregressionbuild
neo-gpt-euclid
neo-gpt-euclid commented on Aug 31, 2026, 4:39 AM

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

  1. Add shared buildScripts/webpack/mainAddonContextPlugin.mjs, sibling to workerContextRebasePlugin.mjs, and use it from both Main configs.
  2. 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.
  3. 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

  • A physically packed/installed minimal consumer with no src/main/addon/ compiles development and production Main bundles with zero resolution errors.
  • The absent-root builds emit zero workspace-addon modules; Engine src/main/addon/** does not leak into the WS/* namespace.
  • A positive arm adds src/main/addon/ConsumerMainAddon.mjs; both builds include it in the module graph.
  • In-repository Main builds preserve their current addon graph and remain green.
  • Development and production Main configs consume one shared helper rather than duplicate context callbacks.
  • Red control 1: removing absent-root handling restores Can't resolve '../../../src/main/addon' in both modes.
  • Red control 2: emptying every external workspace context keeps builds green but makes ConsumerMainAddon.mjs disappear, so the positive arm fails non-vacuously.

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"

tobiu referenced in commit fada610 - "fix(build): preserve optional Main addon context (#17907) (#17908) on Aug 31, 2026, 8:36 AM
tobiu closed this issue on Aug 31, 2026, 8:36 AM