当创建一个新的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 i npm@latest -g

然后通常使用NPM安装命令

npm install 

其他回答

这为我解决了问题:

以管理员身份打开Windows Powershell

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

https://devblogs.microsoft.com/premier-developer/getting-started-with-node-js-angular-and-visual-studio-code/

我的案例是Windows 7(在需要的时候没有更好的了)。 帮助我如下:

删除c:\ users \username\ appdata \ roam \npm-cache中的所有内容

AND

删除package-lock.json

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

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 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注册表,这可能是有帮助的。检查一下。

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