ChatGPT解决这个技术问题 Extra ChatGPT

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

When creating a new Angular 5 project:

node version: 8.9.2

npm version: 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\_logs\2017-12-06T13_10_10_729Z-debug.log

The error log is here

"npm cache clean --force" without quotes might be the answer to your question.
Worked for me, said it hoped I knew what I was doing. I did not.
sudo npm cache clean --force sudo npm cache verify sudo npm i npm@latest -g These commands worked for me
@tonix thanks bro, your solution is working for me also, npm ERR! Unexpected end of JSON input while parsing near '...lFicG0K5VKDuUbV0\n4AU' (npm install --save firebase-admin)
It is not working for me, I tried multiple times, if I give cache clean next time I get error like npm ERR! sha512-I4kM....

Q
Qonvex620

This solved it for me:

Open Windows Powershell as admin

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/


worked for me! but need to open the terminal as as admin
@McEmmy : I did as you mentioned..but it still pops out the issue Unexpected token , in JSON at position 366360 while parsing near '... } npm ERR! } npm ERR! }, npm ERR! "webpack-log":...'
That works but when I run it under C:\Users\[user-name]\AppData\Roaming\npm main directory
it works but it just frustrating every npm relate problem pretty much all come down to delete node_modules/ or clean cache
What's super annoying for me is that when you're installing hundreds of packages and one of them is failing it's impossible to tell which one. These npm error logs are less than useless.
M
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]

npm install -g @angular/cli@latest

(installing angular cli (or installing anything else))

It will work.

explanation:

https://i.stack.imgur.com/UNJPw.png

https://i.stack.imgur.com/t9jeS.png

https://i.stack.imgur.com/LRrND.png

https://i.stack.imgur.com/INiqo.png

Here a good link from the doc: 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/7668448 it show how you can change the npm registry, that can be helpful. Check and see.


Well explained answer sir thanks a lot I was wondering why this had happening and i suspected that my files got corrupted because of a bad internet connection which caused the cache file to be corrupted since the download wasn't complete could this be true
Yes and an unsure no. Yes that was an issue in the past. As per this issue thread github.com/npm/npm/issues/4652. But they working on it. Now i'm unsure, maybe it is solved. It all depend on the implementation and how npm manage all the steps from fetching to caching to installing. I don't have time to go through npm internal right now. But i'm elaborating around this question, doing some research. I will write an article, and update the answer later when it's done. Know that they may have other reason to the error then a cache corruption,
see docs.npmjs.com/common-errors#invalid-json. For registry problem there is verdaccio that one can try github.com/verdaccio/verdaccio. advised as per those threads github.com/npm/npm/issues/21181, github.com/npm/npm/issues/21112. And here a thread about the cache and how they were moving github.com/npm/npm/issues/4652. Another article which is history now infoworld.com/article/3198746/javascript/…. I let you know when i finish my research and writing an article.
Here an interesting thread: Here an interesting thread github.com/yarnpkg/yarn/issues/393
The issue had bothered me for a while and back with consistent error. Thanks to this post, I deleted the two folders and now things work for me properly! Thanks
M
MD SHAYON

If

npm cache clean --force

doesn't work. try

npm cache clean --force
npm update

This answer should get more votes. updating is an important step and I also wasted almost 3 hours because I wasn't able to find this answer
As of May 2020, this is the only solution that actually works perfectly as intended for the workflow error
No doubt, it is indeed a perfect answer. The only solution worked for me.
+1 from me too, it worked great and indeed the only solution that worked after losing days of trying to fix everything else...
It worked for me as of June 2020. Please Vote this answer
A
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 clean --force

then normally use your npm install command e.g.

npm install -g @angular/cli

P
Paul Roub

I solve that with

npm cache clean --force

then update npm

npm i npm@latest -g

then normally use your npm install command

npm install 

R
Ravinder Reddy Kottabad

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

npm cache clear --force npm cache verify

update npm to latest version

npm i -g npm

then create your project 1)Angular

npm i -g @angular/cli@latest ng new HelloWorld

2)React

npm i -g create-react-app create-react-app react-app


I cannot execute npm i -g npm, getting error npm ERR! Unexpected end of JSON input while parsing near '...am","fstream-npm","gi'
C
Christopher Grigg

None of the 30 answers here worked for me. I needed to:

delete node_modules and package-lock.json npm cache clean --force npm install -g @angular/cli npm i --package-lock-only npm ci

Phew!


wow, that was a few hours wasted I'm never getting back. LOL! that did the job, thank you very much 🐲
Deleting package-lock.json fixed the problem for my Vue.js project on Windows!
This solved my issue: npm cache clean --force Thanks a lot
It works bro. Thanks
W
WasiF

this solved it npm cache clean --force


S
Shashwat Gupta

Simple solutions:

npm cache clean --force
npm install 

H
Hearen

This command alone solved my problem:

npm cache clean --force

Also you should make sure you are using the correct version of node.

Using nvm to manage the node version:

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;

m
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


W
WasiF

npm cache clean --force worked for me

Error Resolved :

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

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


N
Nick

Solution

npm cache clean --force

For Windows : go to C:\Users\username\AppData\Roaming\npm-cache
Delete all files and run

npm install && npm start

D
Desire Kaleba

I solved that by first cleaning the cache using

npm cache clean --force

Then

npm install -g @angular/cli

y
ysvet

My case - Windows 7 (had nothing better at the needed moment). Helped me the following:

Deleting everything from C:\Users\username\AppData\Roaming\npm-cache

AND

Deleting package-lock.json


Deleting package-lock.json fixed the problem for my Vue.js project on Windows!
J
Jean-François Fabre

I resolved my problem with this one liner

npm cache clean --force

Note: since its a clean install, I had no concerns emptying npm cache.


L
Lahiru Amarathunge

ERROR: npm ERR! Unexpected end of JSON input while parsing near '...ore-js":"3.0.0-beta.1

This occurs when installing the expo CLI globally, This works for me!

npm cache clean --force

R
Rijo

I got error (file already exists --force to overwrite) after running the following code:

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

I solved it using :

npm i -g --force npm

Make sure to run the first commands to flush the cache of npm.


b
blackgreen
npm cache clean --force
npm update

Do not forget to do "npm update". it is very important step .


r
raghu rkm

It's error from your npm....

So unistall node and install it again.

It works....

PS: After installing node again, install angular cli globally.

npm install -g @angular/cli@latest

M
Muhammad Tahir

I solve that with

First delete package-lock.json

npm cache clean --force

then update npm

npm i npm@latest -g

then use npm install command

npm install 

j
jhildenbiddle

If npm cache clean --force doesn't resolve the issue, try deleting the ~/.npm directory (*nix/macOS). This is the directory where node stores its cache, locks, logs, global packages (unless you're using nvm), and modules installed via npx.

First, backup your current ~./npm directory:

mv ~/.npm ~/.npm-backup

Now try running your npm command again. This will create a new ~/.npm directory. If the issue is resolved, you can safely remove you backup. Before doing so, you may want to review the global packages installed in your ~/.npm-backup directory so you can reinstall them using npm i -g [package].

rm -rf ~/.npm-backup

If the issue is not resolved, you can restore your backup:

rm -rf ~/.npm
mv ~/.npm-backup ~/.npm

Careful with those rm commands, folks!


O
Overflowrun

If you looking for npm install and getting same kind of error

Delete package-lock.json and npm cache clean --force and try


S
Sercan

In my case I changed the network to a much stronger one and npm install worked perfectly:

npm cache clean --force

G
Gianfranco P.

Instead of clearing the cache you can set a temporary folder:

npm install --cache /tmp/empty-cache

or

npm install --global --cache /tmp/empty-cache

As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use npm cache verify instead. On the other hand, if you're debugging an issue with the installer, you can use npm install --cache /tmp/empty-cache to use a temporary cache instead of nuking the actual one.


m
mtchuente

For me I had to clone my branch again and do npm install


佚名

You can use yarn package manager instead of npm.

It solved this problem for me


M
Mohamad Alhamid

I've faced this issue and I tried all the answers on Stackoverflow but not worked for me, finally I found solution for this issue:

First of all you have to uninstall nodejs and remove all the files related him

Go to "Register Editor" and search for all "nodejs", "node.js" and delete them

Restart your computer

And reinstall nodejs then install angular.

It's worked for me


P
Paul Roub

These commands worked for me

sudo npm cache clean --force

sudo npm cache verify

sudo npm i npm@latest -g

M
Mano Prakash P

Try setting

npm config set strict-ssl false

and then try running,

npm install -g @angular/cli


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now