NPM Install Error:Unexpected end of JSON input whi

2019-01-06 16:01发布

问题:

Create 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: C:\Users\Aashitec\AppData\Roaming\npm-cache_logs\2017-12-06T13_10_10_729Z-debug.log

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

回答1:

This solved it for me

npm cache clean --force

then run

npm install -g @angular/cli@latest



回答2:

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:

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. Forcing clean cache resolve the problem.

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.

if you check the first or the second, the structure is as follow

And each cache file have a json format (and that what get parsed)

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.



回答3:

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


回答4:

this solved it npm cache clean --force



回答5:

If

npm cache clean --force

doesn't work try

npm cache clean --force
npm update


回答6:

npm cache clean --force

then

npm install -g @angular/cli

worked for me



回答7:

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



回答8:

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 


回答9:

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


回答10:

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



回答11:

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;