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

错误日志在这里


当前回答

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

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

唷!

其他回答

这解决了它NPM缓存清理-力

每个人都在说

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.

对我来说,我不得不再次克隆我的分支,并进行npm安装

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

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

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

编码快乐!

更新

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

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

这些命令对我很管用

sudo npm cache clean --force

sudo npm cache verify

sudo npm i npm@latest -g