npm ERR! Unexpected end of JSON input while parsin

2020-06-27 22:33发布

问题:

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.

回答1:

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



回答2:

Delete npm and npm cache in C:\Users\beni\AppData\Roaming and then re-create your app and then it works fine .



回答3:

This solved it for me:

Open Windows Powershell as admin

npm cache clean --force

npm install -g @angular/cli


回答4:

Just follow these steps :

step 1 - install angular CLI
npm install @angular/cli

step 2 - create a new project
ng new NAME_PROJECT and press enter the let the default values

step 3 - open the folder "NAME_PROJECT" and run this cmd :
ng serve