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
Try setting
npm config set strict-ssl false
and then try running,
npm install -g @angular/cli
These commands worked for me
sudo npm cache clean --force
sudo npm cache verify
sudo npm i npm@latest -g
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.
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.
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.
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
npm cache clean --force
npm update
Do not forget to do "npm update". it is very important step .