Ionic 2 Build TypeError: Cannot read property '

2019-02-25 19:52发布

问题:

Ionic 2 failed CLI build giving me the following error: "TypeError: Cannot read property 'AssetUrl' of undefined".

My research lead me to this thread and this one.

Both threads suggest to modify the "package.json" file and to remove the "^" sign in front of the version in "dependencies" and "devDependencies".

I did that and then CLI:

  • ionic rm platform android
  • ionic add platform android
  • and finally: ionic build android

I still get the same error.

At some point in this thread , it suggests using some npm command I am not familiar with (yet), quoting it: "rm -rf node_modules and npm cache clean and a fresh npm install". I don't really understand what is under the hood of all this.

I would be grateful if someone come up with the magic solution to make the build run fine. But also I'd like to understand how "TypeError: Cannot read property 'AssetUrl' of undefined" could be linked with the "package.json"? I don't get why this error lead to that possible solution.

My version are: npm 3.10.3 node 6.7.0 cordova 6.3.1 ionic 2.1.0

Here is my package.json as it looks now afer operating the suggestion read in both threads:

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "build": "ionic-app-scripts build",
    "watch": "ionic-app-scripts watch",
    "serve:before": "watch",
    "emulate:before": "build",
    "deploy:before": "build",
    "build:before": "build",
    "run:before": "build"
  },
  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/compiler-cli": "0.6.2",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/platform-server": "2.0.0",
    "ionic-angular": "2.0.0-rc.0",
    "ionicons": "3.0.0",
    "@ionic/storage": "1.0.3",
    "ionic-native": "2.0.3",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "0.6.21"
  },
  "devDependencies": {
    "@ionic/app-scripts": "0.0.36",
    "typescript": "2.0.3"
  },
  "description": "HelloWorld: An Ionic project",
  "cordovaPlugins": [
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-whitelist",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": []
}

回答1:

I did in CLI within the folder of the projet an "npm install" + take away "^" sign in front of "dependencies" and "devDependencies" in package.json (as advised in the forum threads which are linked in my question). And it solved it.



回答2:

You should also update @angular/compiler-cli to the latest version.

That should do the trick