Home > Software design >  Angular 7 Ionic 4 build failing "TypeError: Cannot read properties of undefined (reading 
Angular 7 Ionic 4 build failing "TypeError: Cannot read properties of undefined (reading 

Time:03-21

I would like some help with a problem with building my Angular 7 & Ionic 4 app...

If I run ng build --prod comand i get the following error:

ERROR in ./node_modules/ionic4-auto-complete/fesm5/ionic4-auto-complete.js
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
TypeError: Cannot read properties of undefined (reading 'kind')
    at isAngularDecoratorMetadataExpression (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:265:35)
    at checkNodeForDecorators (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:77:21)
    at visitNodes (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16144:30)
    at Object.forEachChild (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16370:24)
    at checkNodeForDecorators (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16135:24)
    at Object.forEachChild (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16265:21)
    at checkNodeForDecorators (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16135:24)
    at Object.forEachChild (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16322:24)
    at checkNodeForDecorators (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16135:24)
    at Object.forEachChild (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16333:24)
    at checkNodeForDecorators (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16135:24)
    at Object.forEachChild (C:\MAMP\htdocs\myProject\employeeApp\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:16229:21)

This is my package.json file:

"@angular/animations": "^11.0.7",
"@angular/common": "^7.2.2",
"@angular/core": "^7.2.2",
"@angular/forms": "^7.2.2",
"@angular/http": "^7.2.2",
"@angular/material": "^11.0.3",
"@angular/platform-browser": "^7.2.2",
"@angular/platform-browser-dynamic": "^7.2.2",
"@angular/router": "^7.2.2",
"@auth0/angular-jwt": "^3.0.0",
"@ionic-native/core": "^5.0.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^4.1.0",
"@ionic/storage": "^2.2.0",
"cordova-android": "^8.0.0",
"cordova-browser": "6.0.0",
"cordova-sqlite-storage": "^3.3.0",
"core-js": "^2.5.4",
"ionic4-auto-complete": "^2.8.2",
"moment": "^2.24.0",
"ng2-date-picker": "^2.11.0",
"rxjs": "~6.5.1",
"sass": "^1.49.9",
"tslib": "^1.9.0",
"zone.js": "~0.8.29"

I have been googling this issue for some hours now and have no idea what to do.. this is my first Angular Ionic app so I'm still learning... Am I doing something wrong? Should I use a different build command?

CodePudding user response:

I've been dealing a lot with this issue while developing my first Angular application. Nowhere to be found on the Internet how to deal with this issue, I tried and failed to resolve this error. Until I went to production (in which the error didnt seem to come up at all), and then I found out about buildOptimizer.

We were developing angular 7 app - I had global version 13.0 of Angular, so there was a version mismatch - on my colleague's pc, where he had ang7 installed, he also didnt get the error at all. So I'm assuming it's because of the version mismatch.

Here included snippet of angular.json, where to find the buildOptimizer. Notice you have to change it from true to false.

angular.json

  • Related