Angular4中 “@angular/compiler-cli” 报错的解决方案

发布时间:2019-06-14 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Angular4中 “@angular/compiler-cli” 报错的解决方案脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本人初学Angular,跟着官网教程时通过ng new my-app创建项目后,在ng serve --oPEn时,会报如下错误:
The "@Angular/compiler-cli" package was not PRoperly installed. Error: Error: Cannot find module '@angular/compiler'

The "@angular/compiler-cli" package was not properly installed. Error: Error: Cannot find module '@angular/compiler'
Error: The "@angular/compiler-cli" package was not properly installed. Error: Error: Cannot find module '@angular/compiler'
    at Object.<anonymous> (D:nodejsnode_modules@angularclinode_modules_@ngtools_webpack@1.7.4@@ngtoolswebpacksrcindex.js:14:11)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:nodejsnode_modules@angularclitaskseject.js:10:19)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)

在其它地方搜索了多种解决方案,但不理想。而后在stackoverflow看到的一个可能是外国朋友的帖子:
https://stackoverflow.com/que...
就说很可能是angular没有正确安装,然后结合再看了Angular CLI 的gIThub
https://github.com/angular/an...
果然把这个困扰我大天的烦人问题给解决了,现分享解决方案如下:
1.安装好node和npm,这个自不必多说,我这里指定了npm为淘宝的cnpm,原因你懂的,网速问题......
2.如果你的Angular cli 是1.0.0-beta.28或者更早的版本,必须卸载没商量,命令如下:

cnpm uninstall -g angular-cli
cnpm uninstall --save-dev angular-cli

3.你必须把全局和本地项目的Angular CLI更新到一个新版本:
在全局端:

cnpm uninstall -g @angular/cli
cnpm cache clean
*(或者:cnpm cache verify ,当npm版本>5时)*
cnpm install -g @angular/cli@latest

在你的本地项目端:

rm -rf node_modules dist 
* rmdir /S/Q node_modules dist (在Windows 命令行下)*
* rm -r -fo node_modules,dist (在Windows PowerShell下)*
cnpm install --save-dev @angular/cli@latest
cnpm install

4.此时进入项目目录,输入命令
ng serve --open
应该就没问题了。
呼。。。。。。就是这样的报错,搞的我弄了大半天,现在终于可以再次愉快地撸代码了。。。


PS:另外,为保险起见,我多安装了两个东西

cnpm install -g @angular/compiler-cli
cnpm install webpack -g

这是在问题没解决前出现的缺少这两个插件的情况,补上。

脚本宝典总结

以上是脚本宝典为你收集整理的Angular4中 “@angular/compiler-cli” 报错的解决方案全部内容,希望文章能够帮你解决Angular4中 “@angular/compiler-cli” 报错的解决方案所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。