先运行npm install
然后运行npm update
,然后使用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".
然后检查角度版本,在那里有build-angular。
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)
答案 0 :(得分:2)
我有同样的错误。我用以下命令修复了该问题:
使用以下命令安装build-angular
:
`npm i --save-dev @angular-devkit/build-angular`
然后安装build-ng-packagr
:
`npm i --save-dev @angular-devkit/build-ng-packagr`
最终安装ng-packagr
:
`npm i --save-dev ng-packagr`
注意:已安装软件包的版本将与
angular
版本相关。
我希望是有用的。
答案 1 :(得分:0)
对我有用的是卸载@ angular / cli,然后删除node_modules目录和package-lock.json文件,然后重新安装@ angular / cli。示例:
#npm uninstall @angular/cli@7.1.3
#rm -rf node_modules
#rm package-lock.json
#npm install @angular/cli@7.1.3
答案 2 :(得分:0)
尝试一下 npm install --save-dev @ angular-devkit / build-angular
答案 3 :(得分:0)
您没看过这两行吗?
@angular-devkit/build-angular <error>
@angular-devkit/build-ng-packagr <error>
我今天遇到了类似的问题,并通过npm uninstall @angular/cli@7.3.8
解决了;只是,仅此而已,然后我可以按预期运行ng build --prod --stats-json
。
在卸载之前,存在与您相似的错误,但我的错误是@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