41

hello guys I have this next error when I try run my App from the terminal(linux), when I run this command:

ng serve

and I get this error in my terminal:

AppBlog/blog# ng serve
An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'
Require stack:
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /usr/local/lib/node_modules/@angular/cli/models/architect-command.js
- /usr/local/lib/node_modules/@angular/cli/commands/serve-impl.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js
- /usr/local/lib/node_modules/@angular/cli/models/command-runner.js
- /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng
See "/tmp/ng-ev5aDi/angular-errors.log" for further details.

then i checked out this part :

An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'

this part say that cannot find moduled called: "'@angular-devkit/build-angular/package.json'"

then I cheked out this file in my project but I have this, look:

 "devDependencies": {
 "@angular-devkit/build-angular": "~0.900.3",
 "@angular/cli": "~9.0.3",
 "@angular/compiler-cli": "~9.0.2",
 "@angular/language-service": "~9.0.2",
 "@types/node": "^12.11.1",
 "@types/jasmine": "~3.5.0",
 "@types/jasminewd2": "~2.0.3",
 "codelyzer": "^5.1.2",
 "jasmine-core": "~3.5.0",
 "jasmine-spec-reporter": "~4.2.1",
 "karma": "~4.3.0",
 "karma-chrome-launcher": "~3.1.0",
 "karma-coverage-istanbul-reporter": "~2.1.0",
 "karma-jasmine": "~2.0.1",
 "karma-jasmine-html-reporter": "^1.4.2",
 "protractor": "~5.4.3",
 "ts-node": "~8.3.0",
 "tslint": "~5.18.0",
 "typescript": "~3.7.5"
 }

then i went to google and search and I found this like from stackoverflow and I tried their solution but it does not work and I run the command ng serve again.

what I did wrong?

before nothing , before I added 3 components: login,register and home in my folder : src/app with this command : ng generate component login and I import my component in my file : app.component.ts this way:

/* THIS IS JUST A EXAMPLE VERY SIMILAR TO MY CODE REAL, I just import one component*/
import { Component } from '@angular/core';
import { loginComponent } from './login.component';
@Component({
 selector: 'app-root',
 templateUrl: './app.component.html',
 styleUrls: ['./app.component.css'],
 declarations: [loginComponent], //import my login
})
export class AppComponent {
 title = 'blog';
}

maybe is this part but I dont find a solution, any expert in angular could tell me what I did wrong?

UPDATE

I am continue searching in google and I found this: github/Angular they are saying that I would install npm/angular-cli/node again and I run this command for update my angular cli:

uninstalled ang-cli

npm uninstall @angular/cli

installed the latest

npm install -g @angular/cli@latest

but first I update my npm with this command:

installed the latest npm

npm install -g npm@latest

but it still does not work.

asked Feb 25, 2020 at 23:35
5
  • did you try reinstalling the module? Also downgrade to a version below and check Commented Feb 25, 2020 at 23:44
  • @prosper1 when I try update or reinstall the module with this next command : npm install --save-dev @angular-devkit/build-angular (stackoverflow.com/questions/59136899/…), I get this error or message i mean : npm install --save-dev @angular-devkit/build-angular Commented Feb 26, 2020 at 0:01
  • Did you tried to delete the folder "node_modules" and install all the dependencies other time with npm install --save? Commented Feb 26, 2020 at 9:38
  • The solution you describe in UPDATE worked for me. Commented Jun 8, 2020 at 7:09
  • you need to check the version of node. @angular/cli ~9.0.3 will only work with node ^10.13.0 || ^12.11.0 see: runebook.dev/ru/docs/angular/guide/versions Commented Jan 17, 2024 at 18:27

17 Answers 17

18

Please try installing the npm on a project folder. I had installed npm globally but installing the npm once again on a solution folder fixed my issue.

npm install in the project folder will do the trick. Then do ng serve -o

answered Apr 9, 2020 at 9:53
Sign up to request clarification or add additional context in comments.

3 Comments

npm install in the solution folder will do the trick. Then do ng serve -o
What does the '-o' do in the 'ng serve -o'?
@EvanSevy opens a browser to the app
14

I finally found something working for me.

Add --force at the end of your npm command.

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

Then ng serve

answered Apr 7, 2021 at 14:00

Comments

8

In my case these 2 commands helped:

npm install -g npm@latest
npm install -g @angular/cli
double-beep
5,66019 gold badges43 silver badges50 bronze badges
answered Feb 27, 2020 at 9:20

Comments

5

I have faced this issue when i recently upgraded the Angular CLI to Angular 9. the following commands fixed the issue.

npm install --save-dev @angular-devkit/build-angular
npm install
ng serve -o
answered Apr 21, 2020 at 16:54

1 Comment

when i do that i get the below error npm ERR! Unexpected end of JSON input while parsing near '...@types/node/-/node-6.' npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\rmahapatra\AppData\Roaming\npm-cache\_logs2020円-08-11T11_04_56_358Z-debug.log
4

If you are on Angular 11 and facing this issue then please do the following:

  1. Remove "@angular-devkit/build-ng-packagr:build" dependency from devDependencies

  2. Update angular.json->projects->your-library-name -> architect -> build ->

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

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

answered Jun 8, 2021 at 20:20

2 Comments

I may be on an older version 9. But I used "@angular-devkit/build-ng-packagr:build" here and it worked. Thanks for the hint on the builder within angular.json
Thanks, finally to much scrolling to find this answer. Angular team, why not add this in the migrations?
2

In my case running npm install in project folder solved the problem.

answered Jan 20, 2021 at 5:18

Comments

1

In my case 2 commands helped:

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

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

answered Sep 16, 2020 at 1:48

Comments

0

Under the project directory run the following command

npm install --save-dev @angular-devkit/build-angular
answered Dec 21, 2020 at 15:43

Comments

0

The error states that "Cannot find module '@angular-devkit/build-angular/package.json'" which means you have to have that package added.

  1. install the latest npm

    npm install -g npm@latest

  2. add the missing

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

answered Dec 26, 2020 at 21:19

Comments

0

Had this exact issue on an existing Angular 10 project. The following steps resolved the issue for me:

  1. Delete the package-lock.json file.
  2. Delete the node_modules folder and all of its contents.
  3. Run npm install. Note that in my case I had to add the --force flag. YMMV

At this point, ng build --prod completed successfully for me.

answered Jan 14, 2021 at 3:18

Comments

0

I am Working Angular Project When I update Angular Cli and then I get this error An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/utils' Require stack:

  • C:\codeFlies Development\how_marketsapp\node_modules@ionic\angular-toolkit\builders\utils\index.js
  • C:\codeFlies Development\how_marketsapp\node_modules@ionic\angular-toolkit\builders\cordova-build\index.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular-devkit\architect\node\node-modules-architect-host.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular-devkit\architect\node\index.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\models\architect-command.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\commands\run-impl.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\node_modules@angular-devkit\schematics\tools\export-ref.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\node_modules@angular-devkit\schematics\tools\index.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\utilities\json-schema.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\lib\cli\index.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\lib\init.js
  • C:\codeFlies Development\how_marketsapp\node_modules@angular\cli\bin\ng See "C:\Users\hp\AppData\Local\Temp\ng-UQJuET\angular-errors.log" for further details.

I have resolve this error by using this command

npm i @ionic/angular-toolkit@latest

answered Mar 24, 2021 at 9:19

Comments

0

In my case I was getting a similar but different error.

Cannot find module '@nguniversal/builders/package.json'

To fix it I had to run

npm install --save-dev @nguniversal/builders
answered Aug 16, 2021 at 21:41

Comments

0

I fixed it using:

npm i --save-dev @angular-devkit/build-angular --force
npm i @angular/compiler-cli --save-dev
answered Aug 23, 2021 at 13:55

Comments

0

Earlier following were errors:-

ng serve

Following worked for me: -

npm install npm@latest reinstall without -g

Packages installed successfully

answered Aug 29, 2021 at 20:25

1 Comment

Please, try to avoid using images with code and errors, put it as code in your answer instead
0

I personally took 2 days to have a solution for this problem, that was after I upgraded my angular version.

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

It saved my day!

Vinay Somawat
6871 gold badge15 silver badges26 bronze badges
answered Apr 27, 2022 at 12:20

Comments

0

It also happened to me, when I ng serve on the cloned code on the company. This happens because there's an error with node modules installation so we need to install it again, build it, and serve it.

  1. npm install --save-dev @angular-devkit/build-angular
  2. ng build
  3. ng serve

If the first step above, didn't work because it didn't work to me and receives another error which is: "npm ERR! cb() never called!" I solve this using this command: npm cache clean --force and once this worked, continue to steps 2-3. It worked.

Nimantha
6,5156 gold badges32 silver badges78 bronze badges
answered Sep 29, 2021 at 4:11

Comments

-1

npm install run this in your terminal and done.

Arghya Sadhu
45.2k10 gold badges99 silver badges122 bronze badges
answered Aug 31, 2020 at 22:21

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.