当创建一个新的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 install --cache /tmp/empty-cache

or

npm install --global --cache /tmp/empty-cache

从npm@5开始,npm缓存会从损坏问题中自我修复,并且从缓存中提取的数据保证是有效的。如果你想确保所有内容都是一致的,可以使用npm缓存验证。另一方面,如果你正在调试安装程序的问题,你可以使用npm install——cache /tmp/empty-cache来使用一个临时缓存,而不是破坏实际的缓存。

其他回答

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

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

它的工作原理……

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

npm install -g @angular/cli@latest

简单的解决方案:

npm cache clean --force
npm install 

我的案例是Windows 7(在需要的时候没有更好的了)。 帮助我如下:

删除c:\ users \username\ appdata \ roam \npm-cache中的所有内容

AND

删除package-lock.json

这里的30个答案都不适合我。我需要:

删除node_modules和package-lock.json NPM缓存清理——force NPM install -g @angular/cli NPM I——仅包锁 npm ci

唷!

这条命令就解决了我的问题:

npm cache clean --force

此外,您还应该确保使用了正确的节点版本。

使用nvm管理节点版本:

nvm list; # check your local versions;
nvm install 10.10.0; # install a new remote version;
nvm alias default 10.10.0; # set the 10.10.0 as the default node version, but you have to restart the terminal to make it take effect;