Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime error with Angular 9 and Ivy: Cannot read property 'id' of undefined ; Zone

We have an Angular 8 project with tests. We are attempting to upgrade to Angular 9 and went through all the steps in https://update.angular.io/#8.0:9.0l3. This all went smoothly, no issues. The app compiles with no errors and all of the tests run fine. We are getting this error at runtime. When we turn off Ivy, it runs fine so definitely seems related to Ivy.

zone-evergreen.js:659 Unhandled Promise rejection: Cannot read property 'id' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'id' of undefined
at registerNgModuleType (core.js:35467)
at core.js:35485
at Array.forEach (<anonymous>)
at registerNgModuleType (core.js:35481)
at core.js:35485
at Array.forEach (<anonymous>)
at registerNgModuleType (core.js:35481)
at new NgModuleFactory$1 (core.js:35649)
at compileNgModuleFactory__POST_R3__ (core.js:41403)
at PlatformRef.bootstrapModule (core.js:41768) TypeError: Cannot read property 'id' of undefined
at registerNgModuleType (http://localhost:8080/vendor.js:41436:27)
at http://localhost:8080/vendor.js:41454:14
at Array.forEach (<anonymous>)
at registerNgModuleType (http://localhost:8080/vendor.js:41450:17)
at http://localhost:8080/vendor.js:41454:14
at Array.forEach (<anonymous>)
at registerNgModuleType (http://localhost:8080/vendor.js:41450:17)
at new NgModuleFactory$1 (http://localhost:8080/vendor.js:41602:13)
at compileNgModuleFactory__POST_R3__ (http://localhost:8080/vendor.js:46530:27)
at PlatformRef.bootstrapModule (http://localhost:8080/vendor.js:46859:16)
like image 329
Shane Avatar asked Feb 17 '20 14:02

Shane


3 Answers

I try to run build ng build --prod for my Angular app. And it clear show me what problem i have.You can try it to know what you need to fix.

like image 87
Anton Skybun Avatar answered Oct 18 '22 22:10

Anton Skybun


I was finally able to track down the error. I had to comment out all the imported modules in app.component.ts, app.module.ts and shared.module.ts and add each module back one at a time. I finally narrowed it down to the include of angular2-recaptcha. That was including a module called ReCaptchaModule. I'm currently researching how to upgrade or replace that.

Hopefully this is a good troubleshooting tip to others out there.

like image 32
Shane Avatar answered Oct 18 '22 23:10

Shane


try and add "enableIvy": true in ts.config under "angularCompilerOptions" & run ng serve it would give you a more precise description about the error.

like image 3
Katzura Avatar answered Oct 19 '22 00:10

Katzura