Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm ERR! Unexpected end of JSON input while parsing near

when creating a new angular project after running npm install -g @angular/cli I am getting the following error

npm ERR! Unexpected end of JSON input while parsing near '...:"^2.1.0","ntypescrip'

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\Suraj\AppData\Roaming\npm-cache_logs\2019-06-28T06_04_16_049Z-debug.log Package install failed, see above.

like image 697
Navod.Avishka Avatar asked Jun 28 '19 06:06

Navod.Avishka


People also ask

How do I fix unexpected end of JSON input npm installation?

When you try to install a new package from the npm, sometimes you will see this following error due to the cache folder of npm gets corrupted. To fix this error, we need to forcefully clean the cache by using the following command. Now, try to install the package again it will install without any errors.

How do I fix unexpected end of JSON input node JS?

You can solve the "Unexpected end of JSON input" error in the following 3 ways: wrap your parsing logic in a try/catch block. make sure to return a valid JSON response from your server. remove the parsing logic from your code if you are expecting an empty server response.

How do I clear Nodejs cache?

Run: “npm cache clean –force” are both not working and you still can't clear the cache, you can force clear the cache by running: npm cache clean --force or npm cache clean -f . This will force delete the npm cache on your computer.


2 Answers

Try:-

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. If you're sure you want to delete the entire cache, rerun this command with --force.

step 1)

$ npm cache clean --force

or

$ npm cache verify

step 2)

$ npm install -g @angular/cli@latest

or

try uninstalling and installing angular/cli

step 3)

$ npm install --save-dev @angular/cli@latest

step 4)

delete node_modules and run $ npm install

like image 129
Manzer Avatar answered Oct 24 '22 02:10

Manzer


This solved it for me:

Open Windows Powershell as admin

npm cache clean --force

npm install -g @angular/cli
like image 38
shavindip Avatar answered Oct 24 '22 03:10

shavindip