883

After updating to Angular 6.0.1, I get the following error on ng serve:

Could not find module "@angular-devkit/build-angular" from "/home/Projects/myProjectName".
Error: Could not find module "@angular-devkit/build-angular" from "/home/Projects/myProjectName".
    at Object.resolve (/home/Projects/myProjectName/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (/home/Projects/myProjectName/node_modules/@angular-devkit/architect/src/architect.js:132:40)

ng update says everything is in order. Deleting node_modules folder and a fresh npm install install did not help either.

My project is based on ng2-admin(Angular4 version). Here is my package.json dependecies:

 "dependencies": {
    "@angular/animations": "^6.0.1",
    "@angular/common": "^6.0.1",
    "@angular/compiler": "^6.0.1",
    "@angular/core": "^6.0.1",
    "@angular/forms": "^6.0.1",
    "@angular/http": "^6.0.1",
    "@angular/platform-browser": "^6.0.1",
    "@angular/platform-browser-dynamic": "^6.0.1",
    "@angular/platform-server": "^6.0.1",
    "@angular/router": "^6.0.1",
    "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.26",
    "@ngx-translate/core": "^10.0.1",
    "@ngx-translate/http-loader": "^3.0.1",
    "amcharts3": "github:amcharts/amcharts3",
    "ammap3": "github:amcharts/ammap3",
    "angular-table": "^1.0.4",
    "angular2-csv": "^0.2.5",
    "angular2-datatable": "0.6.0",
    "animate.css": "3.5.2",
    "bootstrap": "4.0.0-alpha.6",
    "bower": "^1.8.4",
    "chart.js": "1.1.1",
    "chartist": "0.10.1",
    "chroma-js": "1.3.3",
    "ckeditor": "4.6.2",
    "core-js": "2.4.1",
    "easy-pie-chart": "2.1.7",
    "font-awesome": "4.7.0",
    "fullcalendar": "3.3.1",
    "google-maps": "3.2.1",
    "ionicons": "2.0.1",
    "jquery": "3.2.1",
    "jquery-slimscroll": "1.3.8",
    "leaflet": "0.7.7",
    "leaflet-map": "0.2.1",
    "lodash": "4.17.4",
    "ng2-ckeditor": "1.1.6",
    "ng2-completer": "^1.6.3",
    "ng2-handsontable": "^2.1.0-rc.3",
    "ng2-slim-loading-bar": "^4.0.0",
    "ng2-smart-table": "^1.0.3",
    "ng2-tree": "2.0.0-alpha.5",
    "ngx-uploader": "4.2.4",
    "normalize.css": "6.0.0",
    "roboto-fontface": "0.7.0",
    "rxjs": "^6.1.0",
    "rxjs-compat": "^6.1.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "^6.0.1",
    "@angular/compiler-cli": "^6.0.1",
    "@types/fullcalendar": "2.7.40",
    "@types/jasmine": "2.5.38",
    "@types/jquery": "2.0.41",
    "@types/jquery.slimscroll": "1.3.30",
    "@types/lodash": "4.14.61",
    "@types/node": "6.0.69",
    "codelyzer": "3.0.1",
    "gh-pages": "0.12.0",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "3.2.0",
    "karma": "1.4.1",
    "karma-chrome-launcher": "2.0.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "0.2.0",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "npm-run-all": "4.0.2",
    "protractor": "5.1.0",
    "rimraf": "2.6.1",
    "standard-changelog": "1.0.1",
    "stylelint": "7.10.1",
    "ts-node": "2.1.2",
    "tslint": "5.2.0",
    "tslint-eslint-rules": "4.0.0",
    "tslint-language-service": "0.9.6",
    "typescript": "^2.7.2",
    "typogr": "0.6.6",
    "underscore": "1.8.3",
    "wintersmith": "2.2.5",
    "wintersmith-sassy": "1.1.0"
  }

and my angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ng2-admin": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ],
            "styles": [
              "node_modules/roboto-fontface/css/roboto/sass/roboto-fontface.scss",
              "node_modules/normalize.css/normalize.css",
              "node_modules/font-awesome/scss/font-awesome.scss",
              "node_modules/ionicons/scss/ionicons.scss",
              "node_modules/bootstrap/scss/bootstrap.scss",
              "node_modules/leaflet/dist/leaflet.css",
              "node_modules/chartist/dist/chartist.css",
              "node_modules/fullcalendar/dist/fullcalendar.css",
              "node_modules/handsontable/dist/handsontable.full.css",
              "node_modules/ng2-slim-loading-bar/style.css",
              "src/app/theme/theme.scss",
              "src/styles.scss"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/easy-pie-chart/dist/jquery.easypiechart.js",
              "node_modules/jquery-slimscroll/jquery.slimscroll.js",
              "node_modules/tether/dist/js/tether.js",
              "node_modules/bootstrap/dist/js/bootstrap.js",
              "node_modules/handsontable/dist/handsontable.full.js",
              "node_modules/chroma-js/chroma.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ng2-admin:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "ng2-admin:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ng2-admin:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/easy-pie-chart/dist/jquery.easypiechart.js",
              "node_modules/jquery-slimscroll/jquery.slimscroll.js",
              "node_modules/tether/dist/js/tether.js",
              "node_modules/bootstrap/dist/js/bootstrap.js",
              "node_modules/handsontable/dist/handsontable.full.js",
              "node_modules/chroma-js/chroma.js"
            ],
            "styles": [
              "node_modules/roboto-fontface/css/roboto/sass/roboto-fontface.scss",
              "node_modules/normalize.css/normalize.css",
              "node_modules/font-awesome/scss/font-awesome.scss",
              "node_modules/ionicons/scss/ionicons.scss",
              "node_modules/bootstrap/scss/bootstrap.scss",
              "node_modules/leaflet/dist/leaflet.css",
              "node_modules/chartist/dist/chartist.css",
              "node_modules/fullcalendar/dist/fullcalendar.css",
              "node_modules/handsontable/dist/handsontable.full.css",
              "node_modules/ng2-slim-loading-bar/style.css",
              "src/app/theme/theme.scss",
              "src/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": []
          }
        }
      }
    },
    "ng2-admin-e2e": {
      "root": "",
      "sourceRoot": "",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "ng2-admin:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": []
          }
        }
      }
    }
  },
  "defaultProject": "ng2-admin",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}
Noor
  • 2,071
  • 19
  • 28
ForestG
  • 17,538
  • 14
  • 52
  • 86
  • I deleted the node_modules and package-lock.json folders and then typed npm i on the command line. After that, everything was fine. – Rouhollah Torshizi Apr 21 '21 at 12:22
  • sometimes, you might not have node_modules folder at all, maybe fresh clone. run npm install first. – Janatbek Orozaly May 26 '21 at 23:22
  • Do you have folder node_modules ? For me the same error happened, when I cloned my Angular project through GitHub on different laptop. I didn't push folder node_modules to save space. Because I was on cell phone tethering, I decided do not reinstall all packages, but copy node_modules folder from different project on the same laptop. And it worked! – sam sergiy klok Sep 08 '21 at 19:10
  • 2
    So many identical answers to this question. – Steve Smith Nov 25 '21 at 16:45
  • 2
    @SteveSmith I've already flagged a few, but if you notice such answers in the future, you can custom flag them and leave a link to the original answer to get them cleaned up. – General Grievance Dec 14 '21 at 20:28
  • Hey everyone, if the below answers didn't work even after deleting npm_modules and reinstalling, try deleting package-lock.json and try npm install again. I ran into similar issue once and deleting package-lock.json and doing npm install worked for me back then. Hope this helps. – lakshman_dev Jun 14 '22 at 14:56
  • This one worked for me - https://stackoverflow.com/a/62228823/1461862 – Mauricio Gracia Gutierrez Dec 02 '22 at 01:39

47 Answers47

1334

Install @angular-devkit/build-angular as dev dependency. This package is newly introduced in Angular 6.0

npm install --save-dev @angular-devkit/build-angular

or,

yarn add @angular-devkit/build-angular --dev
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
Ritwick Dey
  • 18,464
  • 3
  • 24
  • 37
  • Exact same error? And the configuration file? are they same as this question? – Ritwick Dey May 15 '18 at 10:23
  • Yes. Well, I did some more exploring on this issue. Turns out that it works fine on my Mac Mini, so it will probably has something to do with my Node setup on Windows. – subzerodeluxe May 15 '18 at 16:32
  • Then try to delete node_module folder & clean cache & install again – Ritwick Dey May 15 '18 at 16:44
  • Try to delete node_module & npm cache... @AmritaSrivastava – Ritwick Dey Jun 24 '18 at 09:09
  • hugo der hungrige [here](https://tutel.me/c/programming/questions/49831485/angular+6+and+karma+39can+not+load+quotangulardevkitbuildangularquot+it+is+not+registered39) said: 1. Update all dependencies and make sure the app itself works as intented 2. Replace every occurrence of @angular/cli with @angular-devkit/build-angular in the karma.conf.js 3. Removing the files and the preprocessor configs from the karma.conf.js completely. This is all defined in the angular.json and should be handled automatically by the @angular-devkit karma plugin. **Doing #3 worked for me** – Daniel Hair Jun 26 '18 at 16:28
  • 10
    Upgrade to angular 7 - the accepted answer fixed the error (have upvoted), but didn't solve the upgrade problem overall. This did https://stackoverflow.com/a/51592138/852806 – JsAndDotNet Nov 21 '18 at 16:30
  • 7
    Thanks for this. I just hit this problem while attempting to follow the Angular tutorial: https://angular.io/guide/quickstart - seems like someone forgot to update the documentation? – Dan King Nov 21 '18 at 20:41
  • I don't know why its called devkit if we still need it on prod? – iamjc015 Dec 07 '18 at 09:19
  • This command is only making the situation bad by removing the angular devkit – Jasmine Jul 15 '19 at 12:45
  • 3
    I had to run in adicional the following command: "npm audit fix --force" – André Luís Tomaz Dionisio Sep 24 '19 at 12:34
  • Seems wonky that I have to execute this command every time I clear out node_modules/. – Alan Cabrera Sep 30 '19 at 17:34
  • just try `yarn` or `npm install` – Fábio BC Souza Oct 14 '19 at 20:19
  • This solution not work for me. if any other solution please update – A.Bhagat Jun 04 '20 at 16:27
  • Question though: if my `package.json` mentioned it needs this package as a dev dependency, why wouldn't NPM fetch it for me, transitively? Seems like a bad UX to me. – hotmeatballsoup Feb 11 '21 at 17:05
  • This issue might occur some times due to restricted environment also. check with IT team for angular repo setup internal. Most of the banking services companies will not accept public artifactories. – Vijay Mar 04 '21 at 15:58
  • Same error. Bad answer. – Philip Rego Dec 08 '22 at 23:38
  • I ran with this command: npm install --save-dev @angular-devkit/build-angular --force – Bằng Rikimaru Jan 11 '23 at 04:06
280
npm update

It worked like a charm.

Ajay Takur
  • 6,079
  • 5
  • 39
  • 55
  • 4
    I moved to a new machine halfway through the angular-tour-of-heroes tutorial and pulled the half baked work from source control. This fixed it. – Riegardt Steyn Aug 15 '18 at 13:41
  • Nothing "half baked" about not checking in the `node modules` folder. This simply rebuilds your node modules based on your package.json. This is perfectly normal thing to do when you check out a new solution. – Liam Jan 14 '19 at 19:25
  • 3
    There might be additional packages that are outdated. Run `ng update --all` to try to update all at the same time. –  Apr 29 '19 at 16:21
  • after i cloned my project in another machine i was having this issue, and this solution worked perfectly, thanks – Ricardo Figueiredo Dec 18 '20 at 22:45
  • this should be the accepted answer. – Max Apr 22 '22 at 16:13
136

for angular 6 and above

The working solution for me was

npm install

ng update

and finally

npm update

The Dead Man
  • 6,258
  • 28
  • 111
  • 193
  • When I do the ng update I got several messages about several specific updates needed. Name Version Command to update -------------------------------------------------------------------------------- @angular/core 4.4.7 -> 8.2.4 ng update @angular/core @ngrx/store 2.2.3 -> 8.3.0 ng update @ngrx/store rxjs 5.5.12 -> 6.5.3 ng update rxjs – Aggie Jon of 87 Sep 03 '19 at 22:47
  • npm i only without ng update and npm upsdate worked for me (Angular 12). Anyway thank you so much! – Uri Gross Oct 28 '21 at 15:02
  • noo doesnt work – Philip Rego Dec 08 '22 at 23:40
36

Need to explicitly get devDependencies.

npm i --only=dev
sachq
  • 672
  • 7
  • 11
  • 3
    This worked for me, same answer in: https://github.com/angular/angular-cli/issues/10661#issuecomment-392149827 – iizAck Jan 11 '19 at 13:58
22

If the following command does not work,

npm install --save-dev @angular-devkit/build-angular

then move to the project folder and run this command:

npm install --save @angular-devkit/build-angular
grg
  • 5,023
  • 3
  • 34
  • 50
  • 3
    npm install --save @angular-devkit/build-angular worked for me but only problem was I was trying to run this command from a command prompt which was not run as an administrator, and I entered to execute this command it was not showing any error nothing only cursor was on wait state then I simply run a cmd with admin in it worked. Thanks – asifaftab87 Mar 09 '19 at 06:16
21

Please follow these five steps.It's definitely worked(my personal experience)

Step 1:npm uninstall -g @angular/cli

Step 2:npm cache clean --force

Step 3:npm install -g @angular/cli@latest

Step 4:npm i

Step 5:ng build

After that,ng serve.

20

I fixed mine by:

  1. Delete node_modules folder.

  2. run npm install

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fes Nguyen
  • 580
  • 5
  • 18
15

All of the above answer are correct but they did not work for me. The only way I was able to make this work was by follow steps/commands:

npm uninstall -g @angular/cli@6.0.8
npm cache clean --force
npm install -g @angular/cli@latest
npm install node-sass -g
ng new MY_PROJECT_NAME
cp -r from_my_old_project to_new_MY_PROJECT_NAME
Dinesh Pallapa
  • 1,172
  • 18
  • 20
grepit
  • 21,260
  • 6
  • 105
  • 81
  • If you are trying to build a library, use `ng new MY_PROJECT_NAME --create-application=false` for the second-to-last command. I had this error on trying to build a library. The `--create-application=false` flag avoids pulling in unnecessary dependencies. (https://angular.io/guide/creating-libraries#getting-started) – VSO Oct 23 '19 at 15:17
  • 1
    worked for me after clearing the npm cache and installing again – Braj Nov 16 '19 at 10:43
11

For Angular 8

Install npm-check-updates package

Run:

$ npm i npm-check-updates
$ ncu -u
$ npm install

This package will update all packages and resolve this issue

Notice: After update If you face this issue:

ERROR in The Angular Compiler requires TypeScript >=3.4.0 and <3.6.0 but 3.6.3 was found instead.

then run:

$ npm install typescript@3.5.3

Source Link

Code Spy
  • 9,626
  • 4
  • 66
  • 46
9

npm install Just type npm install and run.Then the project will run without errors. Or you can use npm install --save-dev @angular-devkit/build-angular

Thisuri
  • 409
  • 4
  • 5
9

Try this one.

npm install

npm update

if it's shows something like this. 

run npm audit fix to fix them, or npm audit for details

Do that!

Elshan
  • 7,339
  • 4
  • 71
  • 106
  • 1
    And when you do that, NPM says 'I sure hope you know what you are doing.'. That gave me the freaks. – Ε Г И І И О Sep 07 '19 at 12:18
  • 1
    upvoted since it helped - although only partially. After doing this I still had some missing peer dependencies which I install following this idea: https://stackoverflow.com/a/51063840/2995907 – dingalapadum Nov 11 '19 at 23:04
8

The following worked for me. Nothing else did, unfortunately.

npm uninstall @angular-devkit/build-angular
npm install @angular-devkit/build-angular
ng update --all --allow-dirty --force
Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
7

Following commands works:

npm install
ng update

-You may see the message "We analyzed your package.json and everything seems to be in order. Good work!"

npm update

Then try dev build

ng build 

I got the error with type script, downgraded to

npm install typescript@">=3.1.1 <3.2

ng build --prod 

All success with prod build.

Below is the working combination

ng --version

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.0
@angular-devkit/build-angular     0.11.0
@angular-devkit/build-optimizer   0.11.0
@angular-devkit/build-webpack     0.11.0
@angular-devkit/core              7.1.0
@angular-devkit/schematics        7.1.0
@angular/cli                      7.1.0
@ngtools/webpack                  7.1.0
@schematics/angular               7.1.0
@schematics/update                0.11.0
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1
Prashant Pimpale
  • 10,349
  • 9
  • 44
  • 84
6

A working solution for me:

  1. Delete the node_modules folder.

  2. Run npm install

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Naeem Bashir
  • 1,937
  • 20
  • 17
5
npm install --save-dev @angular-devkit/build-angular@latest

solved it for me.

Lexy Feito
  • 280
  • 1
  • 8
  • 19
5

First delete node_modules folder

then Restart system

Run npm install --save-dev @angular-devkit/build-angular

and

Run npm install

Pullat Junaid
  • 3,224
  • 3
  • 25
  • 25
4

When we run commands like ng serve, it uses the local version of @angular/cli. So first install latest version of @angular/cli locally (without the -g flag). Then update the cli using ng update @angular/cli command. I thing this should fix the issue. Thanks

This link may help you if you are updating your angular project https://update.angular.io/

Tibin Thomas
  • 742
  • 5
  • 12
4

This error generally occurs when the angular project was not configure completely.

This will work

npm install --save-dev @angular-devkit/build-angular

npm install
4

Just execute the following command and error was solved

  • ng update @angular/cli @angular/core
  • npm uninstall @angular-devkit/build-angular
  • npm install --save-dev @angular-devkit/build-angular

    if this error could not resolve by above command so you update node version

    • npm update npm -g
Rajnikant Lodhi
  • 530
  • 4
  • 13
4

Use:

npm i --save-dev @angular-devkit/build-angular

This code installs @angular-devkit/build-angular as a development dependency.

It was 100% tested.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mojtaba Nava
  • 858
  • 7
  • 17
4

Just update the Angular version and add the below dependency:

ng update

npm update

npm i @angular-devkit/build-angular

https://www.npmjs.com/package/@angular-devkit/build-angular

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prasenjit Mahato
  • 1,174
  • 15
  • 10
4

I had a library which I created in an older version of Angular.

Now that I upgraded to the latest version 11 the build would fail.

Indeed, the builder has changed.

When doing an ng build I was something a somewhat similar error message:

Cannot find module '@angular-devkit/build-ng-packagr/package.json'

In the angular.json file I had to change the builder property:

"builder": "@angular-devkit/build-ng-packagr:build",

with:

"builder": "@angular-devkit/build-angular:ng-packagr",
Stephane
  • 11,836
  • 25
  • 112
  • 175
4
  1. Go to the folder where you created the angular project and the delete the node_modules folder.

  2. Now open the command prompt and enter in the project which you want to run using cd.

  3. Enter the command

npm i

or

npm install

  1. Now the command prompt will start installing the new node_modules files in the project.

  2. When the node_modules gets installed then, run the project using command

    ng s --o

If the above method did not work, then there is some mismatch of the version in npm and then try to install the node_modules.

npm update

Generally, this method should work if not worked then try to run this command:

npm install --save-dev @angular-devkit/build-angular

Details and alternative solution: Could not find module “@angular-devkit/build-angular”.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
3

I struggled with the same problem just a minute ago. My project was generated using the v 1.6.0 of angular-cli.

1. npm update -g @angular/cli

2. editing my package.json changing the line
    "@angular/cli": "1.6.0",
      to
    "@angular/cli": "^1.6.0",

3. npm update

I hope my help is effective ツ

  • 1
    This has nothing to do with not being able to find a module. this just means the angular cli module will be updated for any version 1.6.x – SanSolo Dec 20 '18 at 11:18
3

Try this first

npm install --save-dev @angular-devkit/build-angular

If some error come again for missing packages try

npm install
Sudheer Muhammed
  • 813
  • 8
  • 10
3

That's works for me, commit and then:

ng update @angular/cli @angular/core
npm install --save-dev @angular/cli@latest
Andrey
  • 722
  • 7
  • 11
3

I had the same problem today, after upgrading node from v9 to v10.
My environment is set by docker and I had to remove this command from the my DockerFile :

npm link @angular/cli

It creates a symlink to the directory where node is installed.
I guess the angular/cli module in it do not have the same version as the one in the node_modules dir of my project, and this causes the issue.

v.nivuahc
  • 809
  • 8
  • 8
3

All these answers basically say the same

npm install -D @angular-devkit/build-angular
npm install

But this still may fail if you are in a library project like my-lib which is inside an Angular workspace:

workspace
|-- projects
|    |-- my-lib
|        |-- package.json
|
|-- package.json

In this case, make sure to run npm install not only in the directory workspace/projects/my-lib, but also in workspace directly.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Datz
  • 3,156
  • 3
  • 22
  • 50
2
  • Delete the node_modules.
  • Clear the cache using npm cache clean --verify.
  • And then npm install again.

Works like a charm for me.

Arslan Mir
  • 21
  • 6
2

I faced the same problem.

Surprisingly, it was just because the version specified in package.json was not in the expected format.

I switched from version "version": "0.1" to "version": "0.0.1" and it solved the problem.

Angular needs semantic versioning (also read Semver) with three parts.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cactuschibre
  • 1,908
  • 2
  • 18
  • 36
2

I had the problem with the newest version of @angular-devkit/build-angular (as of writing this, 11.0.5 was only released 17 hours ago).

Our company is using a Nexus Repository Manager as a npm registry (we do not access https://registry.npmjs.org/ directly). The version was so new, that it wasn't included yet in our Nexus yet.

Invalidating the cache of the repository and npm install fixed the issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hinneLinks
  • 3,673
  • 26
  • 40
1

I am facing the same issue since 2 days.

ng -v :6.0.8
node -v :8.11.2
npm -v :6.1.0

Make sure you are in the folder where angular.json is installed. Get into that and type ng serve. If the issue still arises, then you are having only dependencies installed in node_modules. Type the following, and it will work:

npm i --only=dev
juzraai
  • 5,693
  • 8
  • 33
  • 47
  • I used ng --version inside the project. It showed me the list with error. So, it means the list didnt had this package installed properly. When I went outside of the app and checked ng --version, so global one didnt even listed it. So, I guess my yarn installtion didnt install the dev dependencies properly – Swapnil Mhaske Jul 14 '21 at 06:38
1

Unfortunately, none of the provided solutions worked perfectly for me, but grepit's answer inspired me to do the following steps. I uninstalled node.js via my OS (Windows 10) and installed it again. Then installed Angular CLI. Then created a new project, and copied my old project's src file into this new one and the error's gone.

Here are the instructions:

  1. Uninstall node.js via your OS and install it again
  2. npm install -g @angular/cli
  3. Rename your project to YOUR_PROJECT_NAME.old
  4. ng new YOUR_PROJECT_NAME
  5. Run this hello world project (ng serve) to make sure that you won't get the error.
  6. xcopy YOUR_PROJECT_NAME.old\src\*.* YOUR_PROJECT_NAME\src /s
    This is Windows version of copy, change it based on your own OS.
Ahmad
  • 96
  • 1
  • 7
1

From the Ionic forum, this worked for me.

npm i @ionic/angular-toolkit@latest
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ComWizd
  • 190
  • 5
0

running the following worked for me npm audit fix --force

Geared4IT
  • 36
  • 4
0

Delete package-lock.json and do npm install again. It should fix the issue.

** This fix is more suitable when you have created Angular 6 app using ng new and after installing other dependencies you find this error.

Rut Shah
  • 1,093
  • 11
  • 13
0

In my case, the issue is, because of missing dependencies. The dependencies are missing, because I've forgotten to call:

npm install

After calling the above command, all required dependencies are loaded in node_modules, and that is no more issue

Chi Cuong Le
  • 368
  • 2
  • 7
0

Solution

Execute below Command on your CLI :

  • npm install
Abdullah
  • 2,393
  • 1
  • 16
  • 29
0

Try this. It worked for me

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli@next
Til
  • 5,150
  • 13
  • 26
  • 34
0

I try all the answers above, but none of them work to me. I had to downgrade the version of Angular-CLI. I run the command ng --version and results:

@angular-devkit/architect          0.10.7
@angular-devkit/build-angular      0.10.7
@angular-devkit/build-ng-packagr   0.10.7
@angular-devkit/build-optimizer    0.10.7
@angular-devkit/build-webpack      0.10.7
@angular-devkit/core               7.0.7 <-- notice this!
@angular-devkit/schematics         8.2.1
@angular/cli                       8.2.1 <-- and this!
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.0.7
@schematics/angular                8.2.1
@schematics/update                 0.802.1
ng-packagr                         4.7.1
rxjs                               6.3.3
typescript                         3.1.6
webpack                            4.19.1

I open my package.json and search for the line that define the version of CLI:

...
"devDependencies": {
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular-devkit/build-ng-packagr": "~0.10.0",
    "@angular/cli": "~8.2.0" -- I changed here to ~7.0.7
...}
...

I change the version of @angular/cli to ~7.0.7. Then run npm uninstall @angular/cli and install again running npm install -g angular-cli@~7.0.7

deldev
  • 1,296
  • 18
  • 27
0

I resolved this by installing Angular on a 64 bit operating system. I was getting the error because I was initially running it on a 32 bit OS

Pholoso Mams
  • 467
  • 1
  • 5
  • 19
0

With the help of the below commands, your application will work as you expected. Run each command as I mention.

  1. npm list -g --depth=0
  2. npm i npm-check-updates
  3. npm install

And finally, run the below command to open your project in the browser:

ng serve --open
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
abubakkar tahir
  • 737
  • 1
  • 11
  • 13
0

I didn't have a package.json. Make sure you have one.

tblev
  • 422
  • 4
  • 13
0

For me, it worked when I ran the npm install command inside the project folder.

Example: I have shoppingmenu app and I ran the npm install command inside that folder.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pavankumar AN
  • 55
  • 1
  • 12
0

This error mostly arises when you don't have Node.js modules in your Angular application.

Developers mostly share Angular applications without the Node.js node_modules folder, because it is very big in size and sharing of applications or uploading takes so much time.

It can be fixed with single command , npm install.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Asim Khan
  • 31
  • 5
-2

I just did the below, and it worked.

npm install --save-dev
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MadanD
  • 107
  • 5
-5

you npm version is old, try to run the following command:

npm i npm@latest -g
qiulvelu
  • 1
  • 3
  • old npm or Node versions does not throw this error "Could not find module “@angular-devkit/build-angular”, the aswear is just install the dependency:npm install --save-dev @angular-devkit/build-angular – Welyngton Dal Prá May 06 '20 at 19:31