Skip to content

fix: define ngDevMode in dev builds to prevent ReferenceError#1089

Open
rogeru wants to merge 1 commit intoangular-architects:mainfrom
rogeru:fix/ngdevmode-undefined-in-dev
Open

fix: define ngDevMode in dev builds to prevent ReferenceError#1089
rogeru wants to merge 1 commit intoangular-architects:mainfrom
rogeru:fix/ngdevmode-undefined-in-dev

Conversation

@rogeru
Copy link

@rogeru rogeru commented Mar 20, 2026

Summary

In dev mode, ngDevMode was not included in esbuild's define config. Angular's compiler emits bare ngDevMode references for signal(), input(), and computed() debug info. When these execute at module load time, they throw:

ReferenceError: ngDevMode is not defined

This one-line fix sets ngDevMode to 'true' in dev builds (and keeps 'false' for production), ensuring esbuild always replaces the identifier.

The change

- ...(!dev ? { ngDevMode: 'false' } : {}),
+ ngDevMode: dev ? 'true' : 'false',

This also fixes the related issue where isDevMode() always returns false (#552), since ngDevMode is now correctly set to true during development.

Issues

Fixes #458
Fixes #897
Related to #552, #815

In dev mode, `ngDevMode` was not defined at all in the esbuild `define`
config. Angular's compiler emits bare `ngDevMode` references in
signal/input/computed debug info. When these run at module load time,
they throw `ReferenceError: ngDevMode is not defined`.

This sets `ngDevMode` to `'true'` in dev builds (and keeps `'false'`
for production), ensuring the global is always replaced by esbuild.

Fixes angular-architects#458
Fixes angular-architects#897
Related to angular-architects#552, angular-architects#815

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Aukevanoost
Copy link
Collaborator

Thank you for this, a bit of an unfortunate timing but I'll have a look!

I just wanted to point out that both the issues you claim to fix are module-federation related while this fix is for native-federation.

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.

Application bootstrap fails with R3InjectorError and ngDevMode ReferenceError ngDevMode is not defined

2 participants