156

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.

3
  • 1
    have you also tried running sudo npm install?
    – antzshrek
    Commented Oct 3, 2017 at 9:34
  • Yes it did the same Commented Oct 3, 2017 at 9:36
  • 1
    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
    – Trevor
    Commented Jan 3, 2020 at 22:36

21 Answers 21

208

Steps

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

This should help.

5
  • 2
    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 Commented Mar 26, 2020 at 19:33
  • 1
    this works, yes, but deletion and installation take a long time. this solution is not optimal.
    – jasie
    Commented Jul 6, 2020 at 10:52
  • 4
    Now I get "Cannot find module C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js' Commented Jul 9, 2020 at 4:57
  • 1
    @DavidKlempfner you might want to check this other SO answer stackoverflow.com/questions/24721903/…
    – antzshrek
    Commented Jul 9, 2020 at 7:16
  • 1
    deleting node_modules will be faster through the command line: rmdir /s /q node_modules
    – Mike T
    Commented Mar 3, 2021 at 18:46
45

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 npm@latest -g

del npm2
del npm2.cmd

Rolf-schmidiger

8
  • 10
    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.
    – sigmaxf
    Commented Feb 15, 2019 at 18:20
  • 7
    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.
    – Igor
    Commented Mar 8, 2019 at 16:31
  • 1
    also need to rename npx.cmd
    – Reza
    Commented Oct 18, 2019 at 19:12
  • 2
    I deleted the npx files instead of renaming them that worked, new ones were created. Commented Mar 26, 2020 at 19:32
  • 2
    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.
    – Zakk Diaz
    Commented Aug 4, 2020 at 0:19
14

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.

2
  • 2
    @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!
    – OArnarsson
    Commented Oct 3, 2017 at 10:05
  • 1
    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.
    – Ruan
    Commented Nov 5, 2020 at 12:52
9

While trying to solve this issue, I noticed the log : Error "Your cache folder contains root-owned files, due to a bug in previous versions of npm" while "npx create-react-app example_app"

Running sudo npm cache clean --force worked for me.

Context: I was trying to create a react app using npx create-react-app

3
  • 2
    worked for me! (MacBook pro) Commented Dec 6, 2023 at 4:43
  • Using Sudo npm cache clean --force will remove old npm cache and remove the protections as well. You should receive the following warning message but it will work npm WARN using --force Recommended protections disabled. Commented Mar 13 at 11:19
  • 2
    sudo npm cache clean --force worked like a charm! Commented May 18 at 14:55
7

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.

Reinstall the node js with this command and it works fine.

npm install -g npm
5

This worked for me

npm install -g --force gatsby-cli

Thanks

4

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

4

I had a similar issue but was because initially the project was installed with

yarn install

Then when I tried to install dependencies using

npm install 

I caught this same error. So ensure to use only one: yarn or npm. I fixed it by adding my dependency with

yarn add <vendor_name>

but the same works if you use npm instead, you need to add a dependency.

0
3
  1. Uninstall node.js from control panel
  2. Delete below folders
C:\Program Files (x86)\Nodejs
C:\Program Files\Nodejs
C:\Users\{User}\AppData\Roaming\npm (or %appdata%\npm)
C:\Users\{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
C:\Users\{User}\.npmrc (and possibly check for that without the . prefix too)
C:\Users\{User}\AppData\Local\Temp\npm-*
  1. Install node.js again
1

I had a similar error(mine is not @angular),
resolved by deleting and reinstalling node with installer.

1

I had the same problem and it turned out the problem was that a stray instance of npm was running somewhere in the background at the same time I was trying to do the install (it was Webpack's npm run serve, to be precise).

Stopping the running instance resolved the problem.

1

I had a similar problem and what seems to have worked is to uninstall npm and reinstall it, making sure to be logged in as the correct user for the reinstall. I think I previously installed npm as root, but was updating a package as a regular (sudo) user.

1

I had this problem when working on a virtual, encrypted disk. Moving the project to a regular disk solved the problem.

1

I the same error but when I was trying to update module "cordova" to version 9. I fixed it by forcing the install with --force. The npm command I used:

npm i -g --force cordova@9 
1

I downgraded my node version to 10 with nvm, and it installed a newer version of npm (v6) during the process. After that, the package was installed w/o errors. So it's either npm or node version.

1

In my case, when trying to install for example the program mermaid-cli, and with npm being already installed,

npm install @mermaid-js/mermaid-cli

threw the error in question.

When I added --force, the output was just shortened, but the same error:

$ sudo npm install @mermaid-js/mermaid-cli --force
npm WARN using --force I sure hope you know what you are doing.
npm WARN enoent ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm WARN MY_USER No description
npm WARN MY_USER No repository field.
npm WARN MY_USER No README data
npm WARN MY_USER No license field.

npm ERR! code EEXIST
npm ERR! path /home/MY_USER/node_modules/npm/node_modules/.bin/rimraf
npm ERR! Refusing to delete /home/MY_USER/node_modules/npm/node_modules/.bin/rimraf: is outside /home/MY_USER/node_modules/npm/node_modules/rimraf and not a link
npm ERR! File exists: /home/MY_USER/node_modules/npm/node_modules/.bin/rimraf
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-02-03T13_41_52_634Z-debug.log

I then followed the accepted answer that says that you only need to remove and install npm again and therefore removed the directory node_modules from my home directory where it was installed.

Yet, I still ran into the error when running npm install:

$npm install
npm WARN saveError ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm WARN MY_USER No description
npm WARN MY_USER No repository field.
npm WARN MY_USER No README data
npm WARN MY_USER No license field.

up to date in 0.865s
found 0 vulnerabilities

The easy fix for this was to just install the program with npm again when npm 'node_modules are removed! I happened to find out about by entering the command although npm's node_modules were removed. Ran through.

Logs:

$npm install @mermaid-js/mermaid-cli

> [email protected] install /home/MY_USER/node_modules/puppeteer
> node install.js

Downloading Chromium r950341 - 142 Mb [====================] 100% 0.0s 
Chromium (950341) downloaded to /home/MY_USER/node_modules/puppeteer/.local-chromium/linux-950341
npm WARN saveError ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 12"} (current: {"node":"10.19.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
...
npm WARN MY_USER No description
npm WARN MY_USER No repository field.
npm WARN MY_USER No README data
npm WARN MY_USER No license field.

+ @mermaid-js/[email protected]
added 147 packages from 94 contributors and audited 147 packages in 26.338s

10 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Wrap up:

If npm install fails, install whatever program you like or dislike, but install one program with the npm command even if you just have removed npm's node_modules directory. It will download the node_modules again and in my case, the program worked.

0

--force helped to solve it:

npm install -g --force node@^16.10.0 
0

locate the /Users/macbook/.npm/ on macOs and delete the cacahe folder, that works fine for me

0

I had the same error, and in my case is because i forgot i had installed nvm.

If you have nvm installed then you should not try to install npm separately. You must use nvm to install the desired node version and the corresponding npm version will be installed too.

0

When I had is problem on a Mac, had to clean up the cache with these two commands

  • sudo chown -R 501:20 "/Users/doobop/.npm"
  • npm cache verify
0

sudo npm install worked for me on Mac

Not the answer you're looking for? Browse other questions tagged or ask your own question.