当创建一个新的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 cache clean --force
但如果这行不通,那就按照下面的步骤来做。
重新安装npm:重新安装npm有时可以解决与npm本身的冲突和其他问题。要重新安装npm,请执行以下步骤:
Uninstall npm:
npm uninstall -g npm
删除npm缓存文件夹:
npm cache clean --force
安装包支持的新LTS节点。如果节点版本不支持,执行以下命令重新安装npm时可能会收到错误。这是你可能得到的错误类型:
npm犯错!notsup要求:{“节点”:“^ 14.17.0 | | ^ 16.13.0 | | > = 18.0.0 "}
npm犯错!notsup Actual: {"npm":"9.4.0","node":"v16.0.0"}
这样你就可以逃跑了,就像我一样
nvm i 16.13.0
其中“i”是“install”的缩写,和
nvm install 16.13.0
然后重新安装npm:
npm install -g npm
如果上面的方法不管用……您应该尝试下面的步骤
删除node_modules文件夹和package-lock。node_modules文件夹和包锁。Json文件有时会被损坏,导致安装包时出错。要解决这个问题,你可以尝试删除这些文件,然后重新安装你的包:
删除node_modules文件夹:
rm -rf node_modules
删除包锁。json文件:
rm package-lock.json
重新安装软件包:
npm install
ELSE
Use a different version of Node.js: If you are encountering errors while using a specific version of Node.js, you can try switching to a different version to see if the issue is resolved. You can use a version manager such as nvm to manage different versions of Node.js on your system.
Check for malware or virus: If you are still encountering issues, there may be malware or a virus on your system that is interfering with npm. Check your system for malware or viruses and remove any that are found.