Skip to content

fix(esbuild): set ngServerMode in exposed-module bundles - #211

Merged
Aukevanoost merged 1 commit into
mainfrom
fix/exposed-ng-server-mode
Nov 25, 2026
Merged

Aukevanoost merged 1 commit into
mainfrom
fix/exposed-ng-server-mode

Conversation

@Aukevanoost

@Aukevanoost Aukevanoost commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #209

@angular/core 22.2.6 reads ngServerMode without a typeof guard during bootstrap, added by angular/angular@c33b0e3 ("validate the APP_ID value on the server", not listed in the release notes) (bootstrapModuleFactory and the bootstrapApplication/createApplication path):

...(ngDevMode || ngServerMode ? [validAppIdInitializer] : [])   // 22.2.5: ...(ngDevMode ? ...)

In production builds ngDevMode is false, so the read always runs. Angular's own browser build defines ngServerMode, and our shared bundles get NG_SERVER_MODE_BANNER (#157), but exposed-module bundles had neither. An exposed module that bundles @angular/core and bootstraps itself therefore throws ReferenceError: ngServerMode is not defined.

This adds the same banner to the exposed-module build. A define would be wrong because exposed modules also run during SSR; the banner only fills in the value when it is undefined, so the server's true is kept.

Not yet verified end-to-end against a remote on 22.2.6; typecheck, lint and existing tests pass.

@angular/core 22.2.6 reads ngServerMode unguarded during bootstrap, which
throws a ReferenceError in exposed modules that bundle core, since they had
neither a define nor the banner the shared bundles get (#157).
@Aukevanoost
Aukevanoost merged commit 77d0949 into main Nov 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught (in promise) ReferenceError: ngServerMode is not defined

1 participant