62

I run the command npm install -g @angular/cli and after i tried to run my app it says, Cannot find module '@angular/compiler' in the terminal. How can i install the compiler in my package.json in order to compile my application

//package
{
  "name": "Restaurant",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~2.4.9",
    "@angular/compiler": "~2.4.9",
    "@angular/core": "~2.4.9",
    "@angular/forms": "~2.4.9",
    "@angular/http": "~2.4.9",
    "@angular/platform-browser": "~2.4.9",
    "@angular/platform-browser-dynamic": "~2.4.9",
    "@angular/router": "~3.4.9",
    "@types/lodash": "^4.14.50",
    "angular-2-data-table": "^0.1.2",
    "angular2-datatable": "^0.5.2",
    "core-js": "^2.4.1",
    "lodash": "^4.17.4",
    "ng2-date-picker": "^0.2.1",
    "ng2-file-upload": "^1.1.2",
    "ng2-modal": "0.0.25",
    "ng2-pagination": "^2.0.1",
    "ng2-table": "^1.3.2",
    "primeng": "^2.0.1",
    "rxjs": "5.2.0",
    "tinymce": "^4.5.2",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.7"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0-rc.1",
    "@types/jasmine": "2.2.30",
    "@types/node": "^7.0.5",
    "angular/cli": "1.0.0-beta.28.3",
    "codelyzer": "3.0.0-beta.0",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "3.2.0",
    "karma": "1.5.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.6.0",
    "protractor": "5.1.1",
    "ts-node": "2.1.0",
    "tslint": "4.5.1",
    "typescript": "~2.2.1"
  }
}
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
Liska Liskor
  • 2,831
  • 4
  • 17
  • 22

9 Answers9

81

Try to delete that "angular/cli": "1.0.0-beta.28.3", in the devDependencies it is useless , and add instead of it "@angular/compiler-cli": "^2.3.1", (since it is the current version, else add it by npm i --save-dev @angular/compiler-cli ), then in your root app folder run those commands:

  1. rm -r node_modules (or delete your node_modules folder manually)
  2. npm cache clean (npm > v5 add --force so: npm cache clean --force)
  3. npm install
SeleM
  • 9,310
  • 5
  • 32
  • 51
  • error : platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:169:23) – Grenoblois Jul 13 '19 at 22:55
  • Does not work for me I am getting this error E:\projects\htdocs\pproject>ng serve An unhandled exception occurred: Cannot find module '@angular/compiler-cli' See "C:\Users\User\AppData\Local\Temp\ng-n5u98J\angular-errors.log" for further details. – kantsverma Sep 11 '19 at 20:48
  • same problem this did not solve it. same exact error – Mike Dec 18 '19 at 14:16
  • 1
    I encountered same issue while migrating old Version angular project into newer version. This solution worked for me. Please make sure that all 3 steps mentioned are executed successfully. – iAmSavy Jan 02 '21 at 16:11
  • I getting this error `Cannot find module compiler.mjs` and this 3 steps worked for me. Thanks. – Pinaki May 16 '22 at 09:48
  • 1
    You may need to do `npm install --force`. If you have dependencies problems locally and need to install everything form the `package.json` – A.Casanova Feb 24 '23 at 11:21
46

I just run npm install and then ok.

Lasith Niroshan
  • 925
  • 10
  • 18
25

Try this

  1. npm uninstall angular-cli
  2. npm install @angular/cli --save-dev
Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
Rahul Verma
  • 404
  • 8
  • 20
12

Uninstall the Angular CLI and install the latest version of it.

npm uninstall angular-cli

npm install --save-dev @angular/cli@latest
Chamila Maddumage
  • 3,304
  • 2
  • 32
  • 43
7

In my case this was required:
npm install @angular/compiler --save
npm install @angular/cli --save-dev

Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
4

This command is working fine for me ubuntu 16.04 LTS:

npm install --save-dev @angular/cli@latest

Copernicus
  • 29
  • 1
  • 10
Akalyvan
  • 147
  • 1
  • 2
  • 14
4

Just to add to this. You will get this error too, when you are running ng serve not from within your project folder. So always make sure your bash runs from your project folder.

Karl
  • 41
  • 1
  • How to make sure of that? – jukebox May 29 '19 at 06:35
  • Assuming that you are using Visual Studio Code's Terminal / Windows, it'll usually show the directory which directory you are currently within. (Example: C:\Projects\YourCurrentProjectFolder). You can then run your ng serve command when you are within the correct folder. – kosherjellyfish Oct 31 '20 at 20:44
0

All I had to do was remove the import from the affected file.

Bluebaron
  • 2,289
  • 2
  • 27
  • 37
0

In my case I had a mono-repo, like this:

<repo-root>
  |_ package.json
  |_ frontend
       |_ package.json
       |_ ...
  |_ ...

Problem was that I installed ng-mocks into the root-package.json which was of course wrong. I removed it there and installed it to the frontend/package.json. After that all worked fine again.

jlang
  • 929
  • 11
  • 32