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

错误日志在这里


当前回答

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

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

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

npm cache clean --force
npm update
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.

NPM缓存清理——强制对我有用

错误解决:

$ NPM install -g gulp npm WARN已弃用gulp-util@3.0.8: gulp-util已弃用—替换它,请遵循https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5上的指导方针 npm犯错!解析JSON输入时意外结束'…/RGs88STtAtiMP3tCiNdU'

npm犯错!这个运行的完整日志可以在下面找到: npm犯错!C:\Users\admin\AppData\Roaming\ npm-cache_logs \ 2018 - 11 - 20 - t07_38_56_733z debug.log

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

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

我用:

npm i -g --force npm

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

我遇到过这个问题,我尝试了Stackoverflow上的所有答案,但不适合我,最后我找到了这个问题的解决方案:

首先,你必须卸载nodejs,并删除所有与他相关的文件 进入“注册编辑器”,搜索所有“nodejs”,“node.js”并删除它们 重新启动计算机 重新安装nodejs,然后安装angular。

这对我很有效

解决方案:

npm cache clean --force

然后再尝试创建你的应用程序(这里创建一个react应用程序)或安装你要安装的东西。

create-react-app myproject

(创建react应用程序)[在不同的操作中可能出现相同的NPM问题]

npm install -g @angular/cli@latest

(安装angular cli(或安装其他任何东西))

它会起作用的。

解释:

这是一个与npm相关的问题,它是关于缓存被破坏的。即使在npm的新版本中,他们实现了自我修复,这通常保证没有损坏,但似乎效率不高。 强制清理缓存可以解决这个问题。

该错误发生在解析一个缓存文件时,该文件具有json格式。缓存位于~/。npm/ _cache (linux)和%AppData%/npm-cache (windows)。对于我当前的npm版本,当我检查时,有三个目录。

如果你检查第一个或第二个,结构如下

每个缓存文件都有json格式

这里有一个很好的文档链接:https://docs.npmjs.com/cli/cache

[更新]如果这没有解决问题,你可以在这里检查这个答案https://stackoverflow.com/a/50191315/7668448它展示了你如何改变npm注册表,这可能是有帮助的。检查一下。