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

错误日志在这里


当前回答

这个错误可能是由许多不同的原因引起的。也许你的全局包以某种方式损坏了,我建议执行以下操作。

1 Install Node Version Manager (or NVM for Windows) and install Node version 10.16.1. This is enough for angular 9 and from my experience, it is the most stable version for development. This should also change your NPM version so that may also help.

2 Uninstall global angular package npm uninstall -g @angular/cli

3 Force clear cache npm cache clean --force

4 You can also try clearing your %temp% and %roaming% AppData/npm-cache

5 install latest angular package npm install -g @angular/cli@<your-version>

6 if this error still occurs, consider using another shell.

源- https://www.codegrepper.com/code-examples/javascript/npm +犯错% 21 +意外+终端+ + JSON +输入+ +分析+在+ % 27时…babel-plugin-istanbul % 27 + npm +犯错% 21 + + +日志+完整的+ + + +可以运行+发现+ % 3 + npm +犯错% 21 + 3 C % % 5 cusers % 5 csapho % 5 cappdata % 5 croaming % 5 cnpm-cache % 5 c_logs % 5 c2020-08-26t20_37_45_303z-debug.log +流产+安装。

其他回答

尝试设置

NPM配置strict-ssl为false

然后试着跑步,

NPM install -g @angular/cli

解决方案

npm cache clean --force

Windows:进入“c:\ users \username\ appdata \ roam \npm-cache”目录 删除所有文件并运行

npm install && npm start

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

npm cache clean --force

每个人都在说

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.

If

npm cache clean --force

是行不通的。 试一试

npm cache clean --force
npm update