node.js NPM 安装错误:在“...nt-webpack-plugin”附近解析时意外结束 JSON 输入:“0”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47675478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:37:17  来源:igfitidea点击:

NPM Install Error:Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'

node.jsangularnpmnpm-install

提问by kathir

When Creating a new Angular 5 project:

创建新的 Angular 5 项目时:

node version: 8.9.2

节点版本:8.9.2

npm version: 5.5.1

npm 版本:5.5.1

My Command is

我的命令是

npm install -g @angular/cli

the Error is

错误是

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\_logs17-12-06T13_10_10_729Z-debug.log

the error log is http://www.aashitechno.in/2017-12-06T13_10_10_729Z-debug.log

错误日志是http://www.aashitechno.in/2017-12-06T13_10_10_729Z-debug.log

回答by mcemmy

This solved it for me:

这为我解决了:

Open Windows Powershell as admin

以管理员身份打开 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/

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

回答by Mohamed Allal

Solution:

解决方案:

npm cache clean --force

then try again to create your app (here when creating a react app) or install what you were about to install.

然后再次尝试创建您的应用程序(创建反应应用程序时在此处)或安装您将要安装的内容。

create-react-app myproject

(creating react app)[same npm problem that can occur in different operation]

(创建react app)[不同操作中可能出现的相同npm问题]

npm install -g @angular/cli@latest

(installing angular cli (or installing anything else))

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

It will work.

它会起作用。

explanation:

解释:

That's a problem related to npm, it's about the cache that get corrupt. Even though in newer versions of npm they implemented self healing, which normally guarantee no corruption, but it seem it's not that efficient. enter image description hereForcing clean cache resolve the problem.

这是一个与 npm 相关的问题,它与缓存损坏有关。即使在较新版本的 npm 中,它们实现了自我修复,通常可以保证不会损坏,但似乎效率不高。 在此处输入图片说明强制清理缓存解决了问题。

The error happen when parsing one of the cache files, which have a json format. The cache is found at ~/.npm/_cacache (in linux) and %AppData%/npm-cache (windows). For my current npm version and when i checked, there was three directories.
enter image description here

解析具有 json 格式的缓存文件之一时会发生错误。缓存位于 ~/.npm/_cacache(在 linux 中)和 %AppData%/npm-cache(在 Windows 中)。对于我当前的 npm 版本,当我检查时,有三个目录。
在此处输入图片说明

if you check the first or the second, the structure is as follow enter image description here

如果你检查第一个或第二个,结构如下 在此处输入图片说明

And each cache file have a json format (and that what get parsed) enter image description here

每个缓存文件都有一个 json 格式(以及解析的内容) 在此处输入图片说明

Here a good link from the doc: https://docs.npmjs.com/cli/cache

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

[Update] Also if it happen that this didn't solve it, you may check this answer here https://stackoverflow.com/a/50191315/7668448it show how you can change the npm registry, that can be helpful. Check and see.

[更新]此外,如果这没有解决它,您可以在此处查看此答案https://stackoverflow.com/a/50191315/7668448它显示了如何更改 npm 注册表,这可能会有所帮助。检查并查看。

回答by MD SHAYON

If

如果

npm cache clean --force

doesn't work. try

不起作用。尝试

npm cache clean --force
npm update

回答by Amit Gaikwad

Npm uses Cache for downloading new packages for you. You need to clear your npm cache. use following command to clean :

Npm 使用 Cache 为您下载新包。您需要清除 npm 缓存。使用以下命令清理:

npm cache clean --force

then normally use your npm install command e.g.

然后通常使用您的 npm install 命令,例如

npm install -g @angular/cli

回答by Ravinder Reddy Kottabad

delete npm and npm-cache folders in C:\Users\admin\AppData\Roaming\ (windows) then execute cmd

删除 C:\Users\admin\AppData\Roaming\ (windows) 中的 npm 和 npm-cache 文件夹,然后执行 cmd

npm cache clear --force

npm cache verify

npm 缓存清除 --force

npm 缓存验证

update npm to latest version

更新 npm 到最新版本

npm i -g npm

npm i -g npm

then create your project 1)Angular

然后创建您的项目 1)Angular

npm i -g @angular/cli@latest

ng new HelloWorld

npm i -g @angular/cli@latest

ng新的HelloWorld

2)React

2)反应

npm i -g create-react-app

create-react-app react-app

npm i -g create-react-app

创建反应应用反应应用

回答by Hasibul-

I solve that with

我用

npm cache clean --force

then update npm

然后更新 npm

npm i npm@latest -g

then normally use your npm install command

然后通常使用您的 npm install 命令

npm install 

回答by BloodLoss

this solved it npm cache clean --force

这解决了它 npm cache clean --force

回答by milad karimi

I use Windows and removed all the files that were listed below and my problem was solved C:\Users{{your-username}}\AppData\Roaming\npm-cache

我使用 Windows 并删除了下面列出的所有文件,我的问题解决了 C:\Users{{your-username}}\AppData\Roaming\npm-cache

回答by user10680309

npm cache clean --forceworked for me

npm cache clean --force对我来说有效

Error Resolved :

错误已解决:

$ npm install -g gulp npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5npm ERR! Unexpected end of JSON input while parsing near '.../RGs88STtAtiMP3tCiNdU'

$ npm install -g gulp npm WARN deprecated [email protected]: gulp-util is deprecated - 按照https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5npm ERR 上的指南替换它!在 '.../RGs88STtAtiMP3tCiNdU' 附近解析时 JSON 输入意外结束

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\admin\AppData\Roaming\npm-cache_logs\2018-11-20T07_38_56_733Z-debug.log

错误!可以在以下位置找到此运行的完整日志:npm ERR!C:\Users\admin\AppData\Roaming\npm-cache_logs\2018-11-20T07_38_56_733Z-debug.log

回答by Shashwat Gupta

Simple solutions:

简单的解决方案:

npm cache clean --force
npm install