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

Then

npm install -g @angular/cli

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

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 +流产+安装。

你可以使用yarn包管理器而不是npm。

它为我解决了这个问题

由于缓存或节点包管理器的过时版本,会发生这种情况 我刚刚更新了我的NPM,它工作得很好 下面是更新Npm到最新版本的命令

npm i npm@latest -g

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

解决方案:

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