当创建一个新的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

错误日志在这里


当前回答

在我的例子中,我把网络换成了一个更强大的网络,npm安装工作得很好:

npm cache clean --force

其他回答

这为我解决了问题:

以管理员身份打开Windows Powershell

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

https://devblogs.microsoft.com/premier-developer/getting-started-with-node-js-angular-and-visual-studio-code/

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安装

Npm使用缓存下载新包。 你需要清除你的npm缓存。 使用以下命令进行清洁:

npm cache clean --force

然后通常使用NPM安装命令 如。

npm install -g @angular/cli

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

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

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

编码快乐!

更新

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

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