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

此外,您还应该确保使用了正确的节点版本。

使用nvm管理节点版本:

nvm list; # check your local versions;
nvm install 10.10.0; # install a new remote version;
nvm alias default 10.10.0; # set the 10.10.0 as the default node version, but you have to restart the terminal to make it take effect;

其他回答

If

npm cache clean --force

是行不通的。 试一试

npm cache clean --force
npm update

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

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缓存清理——force

尝试执行admin文件夹下的安装cmd。 即 C:\Users\admin 这对我来说很有效。

简单的解决方案:

npm cache clean --force
npm install