Fix EEXIST error during npm install

Refusing to delete npm.cmd ERR in NVM for Windows

Hyunbin
1 min readMar 28, 2022

Error

When installing npm globally in NVM for Windows, theEEIXST error occurs.

C:\windows\system32>npm i -g npm@latest
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm.cmd
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

Solution

  1. Run CMD(Command Prompt) as administrator
  2. Uninstall and reinstall Node.js version using nvm (un)install <version>
  3. Open an explorer window and open C:\Program Files\nodejs directory
  4. Install specific version of npm (globally) using npm i -g npm@<version>
  5. After the installing process has started, delete or remove the following files
- ‪C:\Program Files\nodejs\npm
- ‪C:\Program Files\nodejs\npx
- ‪C:\Program Files\nodejs\npm.cmd
- ‪C:\Program Files\nodejs\npx.cmd

The following is an example of a successful installation (update).

C:\windows\system32>npm i -g npm@latest
C:\Program Files\nodejs\npm -> C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
C:\Program Files\nodejs\npx -> C:\Program Files\nodejs\node_modules\npm\bin\npx-cli.js
+ npm@8.5.5
added 57 packages from 18 contributors, removed 315 packages and updated 143 packages in 41.254s

--

--

Hyunbin
Hyunbin

Written by Hyunbin

Node.js and web developer using TypeScript. Undergraduate in Seoul National University.

No responses yet