4

After running npm install then npm update I got this error when using ng serve:

Could not find module "@angular-devkit/build-angular" from "C:\\Users\\Matt\\Coding\\chart".
Error: Could not find module "@angular-devkit/build-angular" from "C:\\Users\\Matt\\Coding\\chart".

Then checking the angular version, build-angular is there.

ng version

--

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.11.0 (cli-only)
@angular-devkit/build-angular      <error>
@angular-devkit/build-ng-packagr   <error>
@angular-devkit/core               7.1.0 (cli-only)
@angular-devkit/schematics         7.1.0 (cli-only)
@schematics/angular                7.1.0 (cli-only)
@schematics/update                 0.11.0 (cli-only)
ng-packagr                         <error>
rxjs                               6.3.3 (cli-only)
typescript                         3.1.6 (cli-only)
coder
  • 239
  • 2
  • 3
  • 14

4 Answers4

3

I have the same error. I fixed with follow commands:

  1. install build-angular with this command:

      `npm i --save-dev @angular-devkit/build-angular`
    
  2. then install build-ng-packagr:

      `npm i --save-dev @angular-devkit/build-ng-packagr`
    
  3. finally install ng-packagr:

      `npm i --save-dev ng-packagr`
    

note: the version of installed package will be related with angular version.

I hope is useful.

AminRostami
  • 2,585
  • 3
  • 29
  • 45
1

What worked for me was uninstall my @angular/cli , then removed node_modules directory and package-lock.json file, then reinstall @angular/cli. Example:

#npm uninstall  @angular/cli@7.1.3
#rm -rf node_modules
#rm package-lock.json
#npm install  @angular/cli@7.1.3
tocode
  • 115
  • 1
  • 10
  • Would you lilke to improve this answer by adding more explanation and maybe some details on "How?". Think of the beginners who might want to use your advice. – Yunnosch Jan 27 '19 at 09:34
  • 1
    `package-lock.json` is automatically generated for any operations where npm modifies either the `node_modules` tree, or `package.json`. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates. Source: https://docs.npmjs.com/files/package-lock.json – karel Jan 27 '19 at 09:36
0

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

-1

Haven't you seen these two lines?

@angular-devkit/build-angular      <error>
@angular-devkit/build-ng-packagr   <error>

I encountered similar issues today and solved by npm uninstall @angular/cli@7.3.8; just that, nothing more and then I can run ng build --prod --stats-json as expected.


Before uninstallation, there is the error similar to yours but mine is @angular-devkit/build-ng-packagr.

$ ng build --stats-json
Could not find module "@angular-devkit/build-ng-packagr" from "/home/hearen/git/repos/ng-hue-lib".
Error: Could not find module "@angular-devkit/build-ng-packagr" from "/home/hearen/git/repos/ng-hue-lib".
    at Object.resolve (/home/hearen/git/repos/ng-hue-lib/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (/home/hearen/git/repos/ng-hue-lib/node_modules/@angular-devkit/architect/src/architect-legacy.js:153:40)
    at Observable._trySubscribe (/home/hearen/git/repos/ng-hue-lib/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:44:25)
    at Observable.subscribe (/home/hearen/git/repos/ng-hue-lib/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:30:22)
    at /home/hearen/git/repos/ng-hue-lib/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:99:19
    at new Promise (<anonymous>)
    at Observable.toPromise (/home/hearen/git/repos/ng-hue-lib/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:97:16)
    at BuildCommand.initialize (/home/hearen/git/repos/ng-hue-lib/node_modules/@angular/cli/models/architect-command.js:67:96)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)

...

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.13.8
@angular-devkit/build-angular      0.13.8
@angular-devkit/build-ng-packagr   <error>
@angular-devkit/build-optimizer    0.13.8
@angular-devkit/build-webpack      0.13.8
@angular-devkit/core               7.3.8
@angular-devkit/schematics         7.3.8
@angular/cdk                       7.3.7
@angular/cli                       7.3.8
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.3.8
@schematics/angular                7.3.8
@schematics/update                 0.13.8
ng-packagr                         5.0.1
rxjs                               6.4.0
typescript                         3.1.6
webpack                            4.29.0
Hearen
  • 7,420
  • 4
  • 53
  • 63