6

I am getting this error when I trying to run ng serve from my terminal window.

An unhandled exception occurred: Cannot find module '@angular/compiler-cli/ngcc'

Below is my package.json file

{
  "name": "ProjectDetails",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --extract-css",
    "build": "ng build --extract-css",
    "build:ssr": "npm run build -- --app=ssr --output-hashing=media",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/platform-server": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^3.4.1",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.1",
    "@angular/cli": "^8.3.1",
    "@angular/compiler-cli": "^5.2.11",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^5.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  },
  "optionalDependencies": {
    "node-sass": "^4.9.0"
  }
}

My angular global version matches the angular/cli version in package .json. They both are 8.3.1. Below is the image for ng --version. I did both the command below, but still getting the same error:

npm uninstall -g @angular/cli
npm install -g @angular/cli

any help will be higly appreciated.

enter image description here

2 Answers 2

7

After running these:

npm uninstall -g @angular/cli
npm install -g @angular/cli

Do this:

npm install

If npm audit fix is prompted, run it.

Sign up to request clarification or add additional context in comments.

3 Comments

I ran npm install command right after the first two command and still got the same error. I am also getting this message saying run npm audit fix to fix them, or npm audit for details
Run npm audit fix if it is prompted
Run npm update and ng serve, if you continue to have a problem, run npm update again and try.
0

I think your problem is with your versions. I mean you are using so many different versions and they could not work well together

let me explain:

Angular CLI: 8.3.5 (latest version)

but for cdk, for 1 year ago: "@angular/cdk": "^6.4.2", "@angular/common": "^6.1.0",

typescript: 3.5.3 ( which probably wasn't there when angular 6.4 exist)

try what I suggest: (I struggled so many times with old project)

Lucky shot: just run ng update --all=true --force=true (look at documentation for correct syntax) it might work, but even if it throw some exceptions, it provide guidelines which reference has a problem)

Create a new angular project by using "ng new projectname"

a. Use "ng serve" to start your project If it works fine, you will be sure that your npm and node works fine (which is very important because it eliminates so many bug possibilities) (if it isn't, honestly reinstalling windows is almost fastest way)

b. after having a working template, just start adding other references to be sure that you dont have version mismatch (and don't forget ng serve and watching the output result). If you had version mismatch, try to upgrade them, or if not possible remove them (if it's an old library, you have to replace it anyway)

c. If it works with any problems, then ship your old code to this new folder and to try to remove your bugs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.