Search code examples
nativescriptnativescript-angular

How do I fix my "Failed to find module: "@angular/compiler" error?


I've upgraded to the latest nativescript, typescript and using angular. Now whenever I try to compile, I get this error, regardless of the platform I am compiling to.

Error: com.tns.NativeScriptException: Failed to find module: "@angular/compiler", relative to: app/tns_modules/

below are my package.json dependencies:

    "dependencies": {
    "@angular/animations": "~6.1.0",
    "@angular/common": "~6.1.0",
    "@angular/core": "~6.1.0",
    "@angular/forms": "~6.1.0",
    "@angular/http": "~6.1.0",
    "@angular/platform-browser": "~6.1.0",
    "@angular/platform-browser-dynamic": "~6.1.0",
    "@angular/router": "~6.1.0",
    "async-await": "^0.1.40",
    "lodash": "^4.17.10",
    "moment": "^2.22.0",
    "nativescript-angular": "^6.1.0",
    "nativescript-audio": "^5.0.0",
    "nativescript-drop-down": "^4.0.1",
    "nativescript-orientation": "^2.2.0",
    "nativescript-theme-core": "^1.0.4",
    "nativescript-ui-listview": "3.5.9",
    "nativescript-ui-sidedrawer": "^4.1.1",
    "nativescript-unit-test-runner": "^0.3.4",
    "nativescript-videoplayer": "^4.1.0",
    "nativescript-webview-interface": "^1.4.2",
    "nativescript-xmlobjects": "^1.1.4",
    "node-sass": "^4.9.2",
    "reflect-metadata": "~0.1.8",
    "rxjs": "^6.0.0",
    "tns-core-modules": "^4.2.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.10.3",
    "@angular/cli": "^7.0.3",
    "@angular/compiler": "^6.1.10",
    "@angular/compiler-cli": "~6.1.0",
    "@types/lodash": "4.14.68",
    "@types/node": "~6.0.60",
    "babel-traverse": "^6.26.0",
    "babel-types": "^6.26.0",
    "babylon": "6.4.5",
    "jasmine-core": "^3.1.0",
    "karma": "^3.1.1",
    "karma-jasmine": "^1.1.1",
    "karma-nativescript-launcher": "^0.4.0",
    "lazy": "1.0.11",
    "nativescript-dev-sass": "^1.6.0",
    "nativescript-dev-typescript": "^0.7.4",
    "nativescript-dev-webpack": "^0.16.3",
    "tns-platform-declarations": "^3.4.1",
    "ts-node": "~3.3.0",
    "tslint": "^5.8.0",
    "typescript": "~2.7.2",
    "webpack": "^4.23.1",
    "webpack-dev-server": "^3.1.10"
  },

Solution

  • @angular/compiler supposed to be under dependencies, not devDependencies. Also with latest version, they use @ngtools/webpack instead of the actual webpack package.

    So it could be better if you compare your package.json with the one in the default template and make necessary changes.