当创建一个新的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到最新版本的命令

npm i npm@latest -g

更新NPM后运行你想要的命令

其他回答

在运行以下代码后,我得到了错误(文件已经存在——强制覆盖):

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

我用:

npm i -g --force npm

确保运行第一个命令来刷新npm的缓存。

以管理员身份打开windows PowerShell或CMD

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

如果这行不通,试试下面的方法

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

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

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

npm cache clean --force

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

npm install -g @angular/cli

每个人都在说

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.