question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular13.1.2 works well in production mode but throws error in development mode

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

// ...
            "development": {
              "buildOptimizer": false,
              "optimization": true, // if set it to `false`, app throws error
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            },

My project has been constructed on the basis of Angular2(beta) since 2016。 Now I prepare to upgrade it from Angular8 to Angular13. After updating angular and related npm packages, and adjusting so much code, the app works well! But only in production mode, which means I have to set “optimization” to true.

If I set “optimization” to false, after the app navigated from home page to any other route, it would throw an error in the console:

Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'ɵmod')

So is there a bug in Compiler or Router? Or any problem in my way?

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'ɵmod')
TypeError: Cannot read properties of undefined (reading 'ɵmod')
    at getNgModuleDef (core.mjs:1120:29)
    at recurse (core.mjs:21703:21)
    at recurse (core.mjs:21714:17)
    at recurse (core.mjs:21714:17)
    at registerNgModuleType (core.mjs:21699:5)
    at new NgModuleFactory (core.mjs:21821:13)
    at Compiler.compileModuleSync (core.mjs:25011:16)
    at Compiler.compileModuleAsync (core.mjs:25017:37)
    at router.mjs:3982:43
    at doInnerSub (mergeInternals.js:19:19)
    at resolvePromise (zone.js:1213:31)
    at resolvePromise (zone.js:1167:17)
    at zone.js:1279:17
    at ZoneDelegate.invokeTask (zone.js:406:31)
    at Object.onInvokeTask (core.mjs:25415:33)
    at ZoneDelegate.invokeTask (zone.js:405:60)
    at Zone.runTask (zone.js:178:47)
    at drainMicroTaskQueue (zone.js:582:35)
    at invokeTask (zone.js:491:21)
    at ZoneTask.invoke (zone.js:476:48)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 13.1.3
Node: 12.20.1
Package Manager: npm 6.14.10
OS: Windows10 x64


+-- @angular-builders/custom-webpack@13.0.0
+-- @angular-devkit/build-angular@13.1.3
+-- @angular/animations@13.1.2
+-- @angular/cli@13.1.3
+-- @angular/common@13.1.2
+-- UNMET PEER DEPENDENCY @angular/compiler@13.1.2
+-- @angular/compiler-cli@13.1.2
+-- UNMET PEER DEPENDENCY @angular/core@13.1.2
+-- @angular/forms@13.1.2
+-- @angular/platform-browser@13.1.2
+-- @angular/platform-browser-dynamic@13.1.2
+-- @angular/router@13.1.2
+-- @compodoc/compodoc@1.1.18
+-- @types/jasmine@3.10.3
+-- @types/jasminewd2@2.0.10
+-- @types/node@12.20.41
+-- @types/qrcode@1.4.2
+-- angular-tree-component@8.5.6
+-- blueimp-md5@2.19.0
+-- bootstrap@3.4.1
+-- co-body@6.1.0
+-- codelyzer@5.2.2
+-- cookie-parser@1.4.6
+-- UNMET PEER DEPENDENCY core-js@3.20.2
+-- cross-env@6.0.3
+-- crypto-js@3.3.0
+-- echarts@4.9.0
+-- ejs@2.7.4
+-- express@4.17.2
+-- fs-extra@8.1.0
+-- html-webpack-plugin@3.2.0
+-- http-proxy@1.18.1
+-- husky@3.1.0
+-- UNMET PEER DEPENDENCY jasmine-core@3.4.0
+-- jquery@1.12.4
+-- jsencrypt@3.2.1
+-- karma@6.3.11
+-- karma-chrome-launcher@3.1.0
+-- karma-coverage@2.1.0
+-- karma-coverage-istanbul-reporter@2.0.6
+-- karma-jasmine@4.0.1
+-- karma-jasmine-html-reporter@1.7.0
+-- karma-mocha-reporter@2.2.5
+-- karma-sourcemap-loader@0.3.8
+-- lint-staged@9.5.0
+-- minimist@1.2.5
+-- moment@2.29.1
+-- ng-zorro-antd@13.0.0
+-- ngx-echarts@4.2.2
+-- prettier@1.19.1
+-- pug@2.0.4
+-- pug-html-loader@1.1.5
+-- qrcode@1.5.0
+-- raw-loader@4.0.2
+-- rxjs@7.4.0
+-- sa-sdk-javascript@1.21.3
+-- serve-favicon@2.5.0
+-- stylelint@12.0.1
+-- stylelint-config-prettier@7.0.0
+-- svgo@1.3.2
+-- tslib@2.3.1
+-- tslint@5.20.1
+-- typescript@4.5.4
+-- UNMET PEER DEPENDENCY webpack@^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0
+-- xlsx@0.15.6
`-- zone.js@0.11.4

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JoostKcommented, Feb 7, 2022

This typically happens when there’s a circular import cycle somewhere in your application. This cycle might disappear in production builds due to optimization passes dropping dead code (and therefore allow certain imports to be removed as well).

You may be able to find all cycles by setting "showCircularDependencies": true in the build architect of the project in angular.json.

0reactions
angular-automatic-lock-bot[bot]commented, Mar 18, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

can't run ng serve in development mode - Stack Overflow
We detected an application built with production configuration. Angular DevTools only supports development builds. ng serve section on angular.
Read more >
Identify and Fix Build and Deployment Errors in Your Angular ...
In this guide, you will learn how to spot some of the most common build and deployment errors and how to resolve them...
Read more >
Upgrading from AngularJS to Angular
Type annotations can be gradually added to existing functions and variables to pin down their types and get benefits like build-time error checking, ......
Read more >
Deploy an Angular Application to IIS - InDepth.Dev
Getting your Angular Router application actually working in a non-root ... and drop it into the root of your Web server and everything...
Read more >
How to Support IE11 Users as You Move to Angular 13 - Bitovi
Internet Explorer 11 is a legacy browser and support for it in Angular ... locally in development mode if you only use differential...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found