npm ERR! Refusing to delete / code EEXIST

143,546

Solution 1

Steps

  1. Delete the node_modules directory completely.
  2. Run npm install again.

This should help.

Solution 2

This was how I solved mine after 'googling' around...

  • Navigate to the directory your node was installed in
  • rename your npm.cmd and npm files
  • Try run the installation again
  • If successful..delete the files you renamed earlier npm and npm.cmd
  • if not, :( :(

The cli commands here...in case you don't want to be renaming and stuffs

cd %ProgramFiles%\nodejs
ren npm.cmd npm2.cmd
ren npm npm2 
npm2 install [email protected] -g

del npm2
del npm2.cmd

Rolf-schmidiger

Solution 3

Try running npm update -g npm then run npm i again.
If that doesn't work maybe npm cache clean helps.

If that doesn't work either you should consider removing the node_modules folder in your application and running npm i again.
If you still have no luck, I suggest removing the package-lock.json and the node_modules folder before running npm i.

Solution 4

For windows users (specific to windows 10) this must solve the problem.

Goto this folder:

C:\Users\[UserName]\AppData\Roaming\

delete or rename the npm and npm-cache folders.

This has fixed my problem in Windows.

Solution 5

I got this problem on Linux (npm is the current latest 5.6.0), because I created a tgz archive, and I needed to --dereference some symlinks (see man tar) when creating a tgz archive (which was them copied to VM for testing). This way a lot of symlinks in node_modules/.bin also became regular files. npm says in the error message, .e.g.

npm ERR! Refusing to delete /path/to/node_modules/.bin/jest: is outside /path/to/node_modules/jest and not a link

Share:
143,546
Azoulay Jason
Author by

Azoulay Jason

Hello world ! I'm a young web developer passionate about video games, music, karate and of course IT. I started with classic PHP/MySQL stack, but recently I fell in love with nodeJS. Today I like to play with Angular, React, Scala, Java, PlayFramework, and lot of other great stuff. Let's keep coding and build the future guys.

Updated on July 08, 2022

Comments

  • Azoulay Jason
    Azoulay Jason 4 months

    I'm just running a simple npm install and i get this error.

    npm ERR! path /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/@angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/.bin/which
    npm ERR! code EEXIST
    npm ERR! Refusing to delete /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/@angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/.bin/which: is outside /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/@angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/which and not a link
    npm ERR! File exists: /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/@angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/.bin/which
    npm ERR! Move it away, and try again
    

    This is the first time I get this error and I don't know what to do.

    • antzshrek
      antzshrek about 5 years
      have you also tried running sudo npm install?
    • Azoulay Jason
      Azoulay Jason about 5 years
      Yes it did the same
    • Trevor
      Trevor almost 3 years
      I also saw this issue when I was hosting a project in a folder that was being synced with Google File Stream. After I moved the project to a "local disk" I was able to run npm install
  • OArnarsson
    OArnarsson about 5 years
    @AzoulayJason I just realized. If you are using the newest verison of the angular CLI it is highly recommended to use yarn instead of npm i. There is some sort of bug related to npm in the latest version. Hope it helps!
  • sigmaxf
    sigmaxf over 3 years
    This answer worked for me, but also I had to rename npx.cmd and npx to npx2.cmd and npx2. I also had to run the terminal as administrator.
  • Igor
    Igor over 3 years
    This worked for me, too. Had to rename npx and npx.cmd as well as npm and npm.cmd. I then did "npm_ update -g npm" and it worked. Perhaps it had something to do with the fact, that I did not install nodejs via an Installer, but rather extracted it from a zip-file instead.
  • Reza
    Reza about 3 years
    also need to rename npx.cmd
  • David Bradley
    David Bradley over 2 years
    I deleted the npx files instead of renaming them that worked, new ones were created.
  • David Bradley
    David Bradley over 2 years
    This failed to install after doing this, with missing npm-cli.js. I ended up doing the rename solution below along with removing npx files
  • jasie
    jasie over 2 years
    this works, yes, but deletion and installation take a long time. this solution is not optimal.
  • David Klempfner
    David Klempfner over 2 years
    Now I get 'npm' is not recognized as an internal or external command.
  • David Klempfner
    David Klempfner over 2 years
    Now I get "Cannot find module C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
  • antzshrek
    antzshrek over 2 years
    @DavidKlempfner you might want to check this other SO answer stackoverflow.com/questions/24721903/…
  • yemiOdetola over 2 years
    @DavidKlempfner check this stackoverflow.com/questions/20992723/…
  • Zakk Diaz
    Zakk Diaz over 2 years
    This worked for me too. @DavidKlempfner run the command using npm2 now that it's renamed. After that I ran into an issue about Refusing to delete `...\npm\node_modules*\node_modules\.bin* I just manually deleted the .bin folders every time it complained (like twice or 3 times) and it worked.
  • Ruan
    Ruan about 2 years
    As of [email protected], 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.
  • Mike T
    Mike T over 1 year
    deleting node_modules will be faster through the command line: rmdir /s /q node_modules
  • Idra
    Idra about 1 year
    just a question... what happens when u reach step #5... thankfully I was not there, but still... I expect to be there by the standards of modern JS
  • havryliuk
    havryliuk 6 months
    I never used yarn and got this error anyway.