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.
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.
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.
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.
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
This solved it for me:
Open Windows Powershell as admin
npm cache clean --force
npm install -g @angular/cli
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With