'Can't install any NPM package, error 4058

I'm trying to install Grunt on my project. It used to work perfectly, but now for some reason, it does not. Every time i try to install Grunt, I got this error:

npm ERR! path C:\irrelevent\path\project\node_modules\ansi-styles
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\irrelevent\path\project\node_modules\ansi-styles' -> 'C:\irrelevent\path\project\.ansi-styles.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Me\AppData\Roaming\npm-cache\_logs\2018-04-03T00_52_10_105Z-debug.log

The weird thing is that the missing package change every time.
I try verifying the cache, removing the node_modules folder, cleaning the cache using --force. Uninstall NPM and NodeJS, restart my computer. No chances.
I had to format my computer for security reason, I took the project folder but not the Roaming folder, I don't know if this had an impact, but it shouldn't since I reinstalled NPM.

I'm not sure if this will help but here is my package.json

{
 "name": "project",
 "version": "2.1.0",
 "repository": "project-2.0",
 "devDependencies": {
   "grunt": "^1.0.2",
   "grunt-cli": "^1.2.0",
   "grunt-contrib-concat": "~1.0.1",
   "grunt-contrib-copy": "^1.0.0",
   "grunt-contrib-cssmin": "~2.0.0",
   "grunt-contrib-jshint": "~1.1.0",
   "grunt-contrib-uglify": "~2.2.0",
   "grunt-contrib-watch": "~1.0.0",
   "grunt-html-build": "^0.7.1",
   "grunt-real-favicon": "^0.2.2"
 },
 "dependencies": {
   "angular-bootstrap-colorpicker": "^3.0.31",
   "angularjs-geolocation": "^0.1.3",
   "sprintf-js": "^1.1.1"
 }
}


Solution 1:[1]

For me the reason was Dropbox (my NodeJS project being somewhere deep in the Dropbox folder). I suspended the synchronisation, tried npm install again and it installed without error. Then of course I resumed the synchronisation.

Solution 2:[2]

you should not forget to goto the project folder by cd "nameofproject" and then "npm start" is work.

Solution 3:[3]

  • delete package-lock.josn and node_modules
  • clear npm cache by npm cache clear --force
  • restart VS Code
  • running npm installagain

Solution 4:[4]

Try this:

  1. Check if you have created an inside folder with the same folder name.

  2. If 2 folders exist with the same name (Delete that 1st folder)

  3. Go to terminal: npm start

Solution 5:[5]

To solve this error for VS-Code:

  1. Close VS-Code
  2. Perform npm cache clear --force
  3. Restart VS-Code.

Solution 6:[6]

I had this same issue, mine is resolved with the help of changing directory (cd frontend) as my project structure was js>frontend>src>index.html

before running npm start, make sure you are in the right directory.

solution

  1. cd frontend (your directory name)
  2. npm start

I installed (npm install -D live-server) and in package.json, I set "start" command as "start":"live-server src--verbose"

Solution 7:[7]

I tried many things like installing different versions , clearing cache , editing environmental variable but nothing works , then on rather than installing nodejs i just extract files of nodejs and it works in my case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fvlinden
Solution 2 Manzurul Hoque Rumi
Solution 3 Kun Zheng
Solution 4 m4n0
Solution 5 flaxel
Solution 6
Solution 7 Amit