当创建一个新的Angular 5项目时:

节点版本号:8.9.2

NPM版本:5.5.1

我的命令是:

npm install -g @angular/cli

错误是:

npm ERR! **Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'**
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Aashitec\AppData\Roaming\npm-cache\_logs\2017-12-06T13_10_10_729Z-debug.log

错误日志在这里


当前回答

以管理员身份打开windows PowerShell或CMD

npm cache clean --force
npm install -g @angular/cli

如果这行不通,试试下面的方法

npm cache clean --force
npm update
npm install -g @angular/cli

其他回答

在解析JSON输入时遇到了意想不到的结束问题。而在我的React应用程序中添加“镭”包。事实上,我甚至在尝试将NPM更新到最新版本时也面临着这个问题。

不管怎样,NPM在清除缓存后无法工作,现在也不会更新到最新版本,但通过Yarn添加包对我来说是有效果的。

所以,如果你急于解决这个问题,但你不能,那么试试yarn,而不是npm。

编码快乐!

更新

在尝试了一些事情后,最后sudo npm缓存清理-force为我工作。

这可能是你的网络或npm注册表中的其他东西的临时故障。

尝试设置

NPM配置strict-ssl为false

然后试着跑步,

NPM install -g @angular/cli

npm uninstall -g angular-cli

npm cache clear --force

OR

删除此文件夹目录(Windows)

rmdir C:\Users\<ProfileName>\AppData\Roaming\npm
rmdir C:\Users\<ProfileName>\AppData\Roaming\npm-cache

简单的解决方案:

npm cache clean --force
npm install 

这是来自npm....的错误

所以卸载节点并重新安装它。

它的工作原理……

PS:重新安装node后,全局安装angular cli。

npm install -g @angular/cli@latest