angular: ReferenceError: ngDevMode is not defined
🐞 bug report
Affected Package
The issue is caused by package @angular/core
Is this a regression?
Not sureDescription
A clear and concise description of the problem...If there are compilation errors in a template (while using “ng serve”), I am seeing the error “ReferenceError: ngDevMode is not defined” when running in Firefox (60.6.1esr) or Edge. Chrome shows the actual compilation errors.
🔬 Minimal Reproduction
https://stackblitz.com/...Create simple app with a component. Introduce compilation errors. Try to run app in browser.
The error (with Angular 8.1.1 is in core.js:13393
🔥 Exception or Error
ReferenceError: ngDevMode is not defined
🌍 Your Environment
Angular Version: 8.1.1 (also 8.1.0)
Anything else relevant?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 14
- Comments: 33 (23 by maintainers)
Commits related to this issue
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): check global ngDevMode is defined before checking value Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): define ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): check global ngDevMode is defined before checking value Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): check global ngDevMode is defined before checking value Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): check global ngDevMode is defined before checking value Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): initialize global ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): initialize global ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): initialize global ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): initialize global ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): initialize global ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
- fix(core): initialize global ngDevMode without toplevel side effects Fix #31595 — committed to filipesilva/angular by filipesilva 5 years ago
Angular 8.2.0, I am using webpack configuration and running into the same issue when the ‘@angular-devkit/build-optimizer/webpack-loader’ is part of the bundling process. I suppose this loadeder removes that variable.
Removing the loader from the rules fixes the issue (but results in not-optimized builds). This can be fixed by injecting the missing variables into the bundle, I have used webpack.DefinePlugin for that:
ngDevMode and ngI18nClosureMode are normally both defined in:
https://github.com/angular/angular/blob/78146c1890b472621acf33d778477db8df816043/packages/compiler-cli/src/tooling.ts
same issue. @angular/core 8.1.2 Is there any way to fix it?
Upd: it happens only for production build. Downgrade of all @angular/* to “~8.0.0” has solved the issue.
Ok, I know what’s going on. If you make a new project and run
ng serve --prod
, the served project has no error.Then if you open
node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js
and remove these line:And run
ng serve --prod
again, you can see this error at runtime:You can work around this problem in your custom webpack setup by importing our provided Terser global definition like we do in Angular CLI.
But I think this is a bug because code in
@angular/core
shouldn’t break when optimized without these definitions.The source line where the error comes from is this one: https://github.com/angular/angular/blob/961d663fbef4d6ea2ebb5a60f38799a273fa71ed/packages/core/src/render3/instructions/lview_debug.ts#L58
There are other similar usages throughout the codebase. It is indeed an error to reference something that isn’t defined. We can see this in a chrome console or node repl:
I think we need to change the code in
@angular/core
to not have errors whenngDevMode
is not defined./cc @kara @mhevery @IgorMinar
Same here, I have this issue in only in production build. Tried to find the reason. Looks like the issue here https://github.com/angular/angular/blob/cb848b94102855d1e773892b25375304102cab69/packages/core/src/render3/instructions/lview_debug.ts#L60 I think it should be replaced with
export const LViewArray = (typeof ngDevMode !== 'undefined') && createNamedArrayType('LView');
cause ngDevMode does not exist in production build, not sure though.@JonWallsten I think when team members paste permalinks they get converted into those snippets automatically. https://github.com/angular/angular/pull/32079 should address this problem.