nvm-windows: Cannot update npm (node 8.4.0)

If this is a question about how to use NVM4W, please use stackoverflow instead.

If this is an issue regarding antivirus, make sure you search the existing issues first.

My Environment

  • Windows 7 or below (not truly supported due to EOL - see wiki for details)

  • Windows 8

  • Windows 8.1

  • Windows 10

  • Windows 10 IoT Core

  • Windows Server 2012

  • Windows Server 2012 R2

  • Windows Server 2016

  • My Windows installation is non-English.

I’m using NVM4W version:

  • 1.1.6
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1.2
  • 1.1.1
  • Older
  • OTHER (Please Specify)

I have already…

  • read the README to be aware of npm gotchas & antivirus issues.
  • reviewed the wiki to make sure my issue hasn’t already been resolved.
  • verified I’m using an account with administrative privileges.
  • searched the issues (open and closed) to make sure this isn’t a duplicate.
  • made sure this isn’t a question about how to use NVM for Windows, since gitter is used for questions and comments.

My issue is related to (check only those which apply):

  • settings.txt
  • proxy support (Have you tried version 1.1.0+?)
  • 32 or 64 bit support (Have you tried version 1.1.3+?)
  • Character escaping (Have you tried version 1.1.6+?)
  • A standard shell environment (terminal/powershell)
  • A non-standard shell environment (Cmder, Hyper, Cygwin, git)

Expected Behavior

npm i -g npm@latest should install latest npm version

Actual Behavior

an error: npm ERR! path C:\Program Files\nodejs\npm.cmd npm ERR! code EEXIST 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! Move it away, and try again.

Steps to reproduce the problem:

run as an administrator npm i -g npm@latest

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 154
  • Comments: 150 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I had the same issue, and here is how I got through :

run npm install -g npm and while it is running: remove(backup) files npm.cmd and npm from c:\Program Files\nodejs\ remove(backup) .bin folder from c:\Program Files\nodejs\node_modules\npm\node_modules, then it should succeed If you have Refusing to deleteissues with any other npm module files/folders you have to just remove these and restart update process. To restart copy npm.cmd back to c:\Program Files\nodejs\ . Then once npm install -g npm is running, remove npm.cmd, otherwise you get in to Refusing to delete npm.cmd issue, you might repeat that process until npm install -g npm is happy.

To remove the files you can use this shortcut: mv npm.cmd "c:\Program Files\nodejs\node_modules\npm\node_modules" as suggested by @farnetani

my env: windows 7 x64, node 8.4, nvm 1.1.6

image

I just remove the npm and npm.cmd files from the nodejs location, move dir node_modules/npm from the nodejs location to another location, and run node npm-cli.js i -g npm@latest inside bin dir in the moved folder.

@kuncevic The easier solution is to copy dir node_modules/npm from the nodejs location, remove the npm bin and cmd, and run node npm-cli.js i -g npm@latest inside bin dir in the copied folder.

Just rename the batch BEFORE upgrading: run cmd

cd %ProgramFiles%\nodejs
ren npm.cmd npm2.cmd
ren npm npm2 
npm2 install npm@latest -g

delete the files after upgrade:

del npm2
del npm2.cmd

I made a batch script to auto run @arfaWong’s solution if anyone’s interested.

@echo off
SETLOCAL EnableDelayedExpansion

if [%1] == [] (
	echo Pass in the version you would like to install, or "latest" to install the latest npm version.
) else (
	set wanted_version=%1

	if "!wanted_version!" == "latest" (
		for /f %%i in ('npm show npm version') do set wanted_version=%%i
	)

	for /f %%i in ('npm -g -v') do set cur_version=%%i

	if "!cur_version!" == "!wanted_version!" (
		echo Already on npm version !wanted_version!.
	) else (
		echo Updating to !wanted_version!...

		set node_path=!PROGRAMFILES!\nodejs

		rename "!node_path!\npm" npm2
		rename "!node_path!\npm.cmd" npm2.cmd
		rename "!node_path!\node_modules\npm" npm2
		node "!node_path!\node_modules\npm2\bin\npm-cli.js" i npm@!wanted_version! -g

		for /f %%i in ('npm -g -v') do set new_version=%%i

		echo New version installed is !new_version!

		if "!new_version!" == "!wanted_version!" (
			echo Successfully updated to !wanted_version!. Cleaning up backups...
			del "!node_path!\npm2"
			del "!node_path!\npm2.cmd"
			@RD /S /Q "!node_path!\node_modules\npm2"
			echo Update complete.
		) else (
			echo Something went wrong. Rolling back.
			if exist "!node_path!\npm" (
				del "!node_path!\npm"
			)
			if exist "!node_path!\npm.cmd" (
				del "!node_path!\npm.cmd"
			)
			if exist "!node_path!\node_modules\npm" (
				@RD /S /Q "!node_path!\node_modules\npm"
			)
			rename "!node_path!\npm2" npm
			rename "!node_path!\npm2.cmd" npm.cmd
			rename "!node_path!\node_modules\npm2" npm
		)
	)
)

They should rename continuous integration to continuous intebreaktion

@arfaWong rocks!!

I used cmder, nvm 1.1.6 and node 8.10.0 Updated from npm 5.6.0 to 5.8.0 🎉

cd %programfiles%/nodejs rm npm npm.cmd mv node_modules/npm node_modules/npm2 node node_modules\npm2\bin\npm-cli.js i npm@latest -g rm -rf npm2

A batch script which works fine. https://gist.github.com/nokidding/aafaf90adc80cbce54b676340817bb13

This works. To use:

  1. download this as updateNpm.bat file
  2. open powershell in that same folder and run this command ./updateNpm.bat latest

@Markus-Hanisch @rsshilli Thank you for that script.

Taking that as a starting point, I’d like to add the following generalized powershell script, which allows you to upgrade NPM regardless of your current Node version and nvm location:

Push-Location (Join-Path (Split-Path (Get-Command nvm).Path) (node --version))
  Move-Item npm npm-old
  Move-Item npm.cmd npm-old.cmd
  Move-Item npx.cmd npx-old.cmd
  Push-Location .\node_modules
    Move-Item npm npm-old
    Push-Location .\npm-old\bin
      node npm-cli.js install -g npm@latest
    Pop-Location
    Remove-Item npm-old -Recurse
  Pop-Location
  Remove-Item npx-old.cmd
  Remove-Item npm-old.cmd
  Remove-Item npm-old -Recurse
Pop-Location

(the only assumption is that nvm stores its versions alongside its exe file, and names them according to the output of node --version)

nvm for Linux has this install-latest-npm command, maybe it is worth integrating the script above in nvm-windows as well.

I created a gist from @kufii’s bat script. Slightly modified so that you can specify the version to install instead of always installing lastet.

https://gist.github.com/johnmcase/d31b799b9030327091a0e74880e4c530

–Edit: Updated to reflect @kufii’s updated script above

This was my fix: 1.Uninstall npm, node, remove all related directories. 2. Remove nvm bloat if any left 3. Install Volta 4. Everything works out of the box + build in rust 5. ??? 6. Profit

Based on @rolf-schmidiger’s answer, I created an update script for it… Kinda sucks that this is the only way I could get it to work.

#!/usr/bin/bash

cd "$PROGRAMFILES"/nodejs
mv npm.cmd npm2.cmd
mv npm npm2
npm2 install -g npm@latest
rm npm2
rm npm2.cmd

UPDATE

This is the latest that is working for me.

#!/usr/bin/bash

cd "$PROGRAMFILES"/nodejs
rm npm npx npm.cmd npx.cmd
mv node_modules/npm node_modules/npm2
node node_modules/npm2/bin/npm-cli.js i -g npm@latest
rm -rf node_modules/npm2/

I think this is more of a previous npm version bug than nvm one.

However, to update npm delete in nvm/[node version] folder (for me it is v10.15.3) following files:

C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npm
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npm.cmd
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npx
C:\Users\[user name]\AppData\Roaming\nvm\[node version]\npx.cmd

Rename npm folder to npm2

C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2

Open any console with admin rights (or even right mouse click on vscode shortcut, than right mouse click on Visual Studio Code and hit Run as administrator) and type commands:

cd C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2\bin
node npm-cli.js i -g npm@latest

Update: as @Fr0sT-Brutal pointed out, admin rights shouldn’t be needed at this point, because we’ve just deleted files that created conflicts 👍

Done.

Delete C:\Users\[user name]\AppData\Roaming\nvm\[node version]\node_modules\npm2 folder.

(This is just step by step reproduce what @19majkel94 said above)

It appears as though npm has changed how it updates itself… without telling anyone. npx was also introduced with only a minor version change (as opposed to a major change)… which is semantically correct, but still hard to follow along.

Apparently there is some file sandboxing happening. I spent the better part of today investigating and attempting a fix, but each fix surfaces another issue. Bear with me, I’ll get it fixed as soon as I can. I’m the only one working on this at the moment… and I happen to be in the middle of a different product launch (after 2yrs of work), so a PR would gladly be accepted.

Problem was being fixed for me like a year ago by switching on mac 😉

I modified this answer for node 15.10.0 and npm 7.5.3 and it very helpful for me. I added one another step for renaming npx too

cd %APPDATA%\nvm\v15.10.0           # or whatever version you're using
mv npm npm-old
mv npm.cmd npm-old.cmd
mv npx npx-old
mv npx.cmd npx-old.cmd
cd node_modules\
mv npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm@latest

I got this work by renaming npm.cmd to npm1.cmd and then deleted other npm files: npm, npx.cmd, npx. Then I ran npm1 install -g npm

@kuncevic

Problem was being fixed for me like a year ago by switching on mac 😉

Corrected: Problem was being avoided by me like a year ago by switching on mac 😉 🤣

So much for production. Good luck doing in a script.

I just renamed these files to “1” npm1.cmd, npm1, npx1, npx1.cmd

and ran: “npm1 update -g

It looks like it worked fine, any thoughts?

This has nothing to do with junctions/hard links/symlinks. @kuncevic provided a screenshot citing npm errors, the key part being Refusing to delete ... which is outside of ..... That is a hard-coded message in npm, preventing further operations. Bottom line: npm is refusing to full update itself.

This didn’t seem to be an issue until npm 5.x.x, and I’m still digging through the details to figure out what has changed. I may have to write a workaround (i.e. hack), which I’m never fond of. I’m also looking into utilizing the msi packages, which seems to be the only way to get the attention of the folks at npm.

If you’re in dire need of updating npm, you can download it via https://github.com/npm/npm/archive/vX.X.X.zip and extract it into the node_modules directory of your node installation root. You’ll need to manually create a symlink in the node installation root to npm.cmd and npx.cmd. The final file structure should look something like:

nvm
- v8.5.0
   - node_modules
       - npm
          - bin
               - npm.cmd
               - npx.cmd
          ...
   - node.exe
   - npm.cmd (symlink to v8.5.0/node_modules/npm/bin/npm.cmd)
   - npx.cmd (symlink to v8.5.0/node_modules/npm/bin/npx.cmd)

I asked CHATGPT and it suggested to upgrade npm with npm install -g npm@latest

If you’re using nvm-windows to manage your Node.js versions on Windows and you want to update npm to X version, you can follow these steps:

  1. Open a Command Prompt or PowerShell window.

  2. Make sure you’re using the Node.js version you want to update by running the following command:

    nvm use <version>
    

    Replace <version> with the Node.js version you want to use.

  3. To update npm, you can use the following command:

    npm install -g npm@X-version
    

    This will install the X version of npm globally on your system.

  4. Once the installation is complete, verify the npm version by running:

    npm --version
    

    You should see the X version of npm that you installed.

By following these steps, you should be able to update npm to the X version using nvm-windows on Windows.

Follow this url to know which version of npm belongs to node https://nodejs.org/en/download/releases

Folks, this is an npm issue, not an NVM4W issue. There is a utility for helping with this, available at https://github.com/felixrieseberg/npm-windows-upgrade.

My solution is NOT very elegant but it works. Here it is. After running npm install npm@5.6 -g I got the following error:

npm ERR! path d:\node\npm.cmd
npm ERR! code EEXIST
npm ERR! Refusing to delete d:\node\npm.cmd: is outside d:\node\node_modules\npm and not a link
npm ERR! File exists: d:\node\npm.cmd
npm ERR! Move it away, and try again.
...

My workaround was the following:

  1. npm install -g yarn
  2. Restart the computer
  3. Run yarn global bin , and add the folder that is displayed to the PATH env variable of Windows
  4. Go to the folder where npm.cmd is located (check this from the error we just got on the npm install npm@5.6 -g run: d:\node\ in my case) and: 2.1. Rename npm to npm.original (or just delete it) 2.1. Rename npm.cmd to npm.cmd.original (or just delete it)
  5. Close the terminal and open a new one
  6. yarn global add npm@5.6
  7. npm install npm@5.6 -g (this will install npm using the npm version located on the yarn global bin folder)
  8. yarn global remove npm (to delete the npm version installed by yarn, and keep only the version installed by npm itself)

How come this 5 years old issue is still not fixed…? I believe original nvm has a special command for upgrading npm and it should be the case here too. Having to rely on some obscure .bat scripts found in comments is ridiculous…

I got around this by using Yarn, which I already had installed.

nvm use 10.0.0

# Have npm remove itself
npm uninstall -g npm

# Install npm into the yarn directory structure
yarn global add npm

# Use npm to install itself into the nodejs directory structure
npm install -g npm

# Remove the yarn installation of npm
yarn global remove npm

A plain Windows DOS version of @ayvarot’s

pushd %ProgramFiles%\nodejs
del npm npm.cmd
move node_modules\npm node_modules\npm2
node node_modules\npm2\bin\npm-cli.js i npm@latest -g
rd node_modules\npm2 /S /Q
popd

For me I only get the problem when updating npm from npm v6. So using a newer version of npm via npx to run the upgrade works for me.

For the newest version
npx npm install -g npm

Or use a specific version
npx npm@7 install -g npm@7

Windows 10 mv npm.cmd "c:\Program Files\nodejs\node_modules\npm\"

and after

npm i -g npm@latest

Solved to me!

@kufii @arfaWong

Thank you!! notworthy

Hello @rsshilli thank you for providing the script. It works quite well and updates npm to the latest version as desired. The only minor issue I faced, was that running npm list -g --depth=0 to list all node packages resulted in two installations of npm. So I simply added some lines of code to remove the “…-old” renamed files and the “…-old” renamed folder. Running npm list -g --depth=0 to list all node packages resulted in one single installation of npm as desired. Here is my updated version of your script: cd %APPDATA%\nvm\v8.9.0 # or whatever version you're using mv npm npm-old mv npm.cmd npm-old.cmd cd node_modules\ mv npm npm-old cd npm-old\bin node npm-cli.js install -g npm@latest

cd %APPDATA%\nvm\v8.9.0 # or whatever version you're using rm npm-old rm npm-old.cmd cd node_modules\ rm -rf npm-old

Here’s my script for upgrading npm on nvm:

https://stackoverflow.com/a/50955293/491553

I just did it on a new install. Works great.

@19majkel94 Please read about junctions. The ‘symlink’ aka window’s shortcut has problems re resolution of target directory from processes. While window’s explorer and terminal seem to handle them nicely, they aren’t handled nicely in other processes. Open notepad, choose open file to get the standard window’s file dialog. Navigate to "C:/Program Files/nodejs" and see where you end up.

Being a redirect to the target directory, which as we see is where processes end up, can lead to some interesting issues.

Junctions are the equivalent of hard links in *nix. Windows only supports these to directories, and not to files, but that’s all we need here. They are not redirects. They are, for all intents and purposes, the directory, no different than the path created when the directory was first created.

They don’t redirect, they are the destination. They can be deleted and created again with each ‘use’ command. Therefore, they will have the same effects and capabilities as shortcuts, but none of the downfalls that are creating the current problem.

Yes folks, volta is an option, as is nodist, fnm, nvs, etc. You’re welcome to use those. I’m going to remove comments about other version managers though, because they don’t help this project improve… and that’s the point of the issues for this project.

For anyone finding this issue from Google, please make sure you’ve read the instructions… specifically the ones about removing any prior versions of Node.js (https://github.com/coreybutler/nvm-windows/wiki/Common-Issues#uninstall-existing-node-installation-before-installing-nvm4w). It is possible to update npm, but you cannot have conflicts in your PATH, or permission restrictions… and there are a few older versions of npm with hardcoded pathing issues. When the v1.1.11 patch release drops, use the debug function to check your environment for potential problems.

I still cannot replicate this problem and there has been a help wanted label for 5 years. I believe it when people say they are still running into npm update problems, but without an environment to test on, it’s really hard to troubleshoot. At this point though, with active development proceeding on Runtime and inconsistency in failures, it’s time to close this issue. If anyone runs into this again, please open a new issue and provide details. It’s important to know things like the specific build of Windows, the locale, whether it’s running in an Active Directory controlled environment or not, whether developer mode is on/off, which shell is running the command, whether the shell is run as an administrator or not, whether there are special characters in your install path or not, whether Node was installed without a version manager before or not, whether another version manager was used before NVM4W, etc.

This ridiculous bug still persists so I made a script that does the job. Must be placed inside Node folder where npm.cmd live.

:: Update NPM with workaround of "npm ERR! code EEXIST" bug https://github.com/coreybutler/nvm-windows/issues/300

@ECHO OFF

SETLOCAL

SET CDir=%~dp0%

REN "%CDir%\npm.cmd" "npm1.cmd"
DEL "%CDir%\npm"
DEL "%CDir%\npx.cmd"
DEL "%CDir%\npx"

CALL "%CDir%\npm1.cmd" update && DEL "%CDir%\npm1.cmd"

Save this as npmup.cmd and use instead of npm update

Windows 10: cd (your nodejs folder) ren npm.cmd npm2.cmd del npm del npx

npm2 install npm -g

del npm2.cmd

I did just rename npm and npx btw, and then delete them afterwards, but I think they could just be deleted straight away.

use yarn instead of npm it self, try yarn global add npm@latest, try to upgrade yarn if this fails.

The solution by @ayvarot worked partially for me. Maybe due to the fact that I was running it on a msys git bash with ConEmu? Anyway, this is my adjusted snippet:

which npm && \
    cd "`which npm | xargs -0 dirname`" && \
    mv npm npm2 && \
    mv npm.cmd npm2.cmd && \
    mv ./node_modules/npm ./node_modules/npm2 && \
    node node_modules/npm2/bin/npm-cli.js i npm@latest -g && \
    rm -r npm2 npm2.cmd ./node_modules/npm2

npm -v

(Using nvm 1.1.6 on node 8.10.0 x32 and updating from npm 5.6.0 to 5.8.0)

@xmedeko wouldn’t npx npm-windows-upgrade run globally unless you’re inside a node project with a local installation of npm-windows-upgrade?

I just renamed these files to “1” npm1.cmd, npm1, npx1, npx1.cmd

and ran: “npm1 update -g

Just rename the file npm1.cmd, it’s enough. Then run the npm update.

No need to use npm-windows-upgrade.

perhaps this can be built into nvm - perhaps by adding an npm version flag along with the node version and architecture flag on install, and an update-nvm function

Here’s my script for upgrading npm on nvm:

https://stackoverflow.com/a/50955293/491553

I just did it on a new install. Works great.

@MrCroft while I agree that it would be nice to have it “just work”, things are far from “hell” and even farther from being “useless”. I’ve been a happy user of this project for something like 2 years now. This problem only occurs when you want to update the global npm itself. Installing new node versions via nvm has no problem and new nodes come with newer npm packages. If you find yourself upgrading npm so often in your dev env that your life becomes hell because of this then you’re probably doing something wrong. I think only twice since I became a nvm user I had to actually upgrade npm itself and hit this problem. Not as bad as you make it sound.

@johnmcase good idea, I updated my comment so you can pass in the version you want to install as an argument (or “latest” to get the latest version)

@arfaWong The only solution that worked guys. Try this out.

I threw together a PowerShell script to automate @arfaWong 's solution: https://gist.github.com/noahleigh/ba34e18b3e0bc4a6a4e93ed7a480536e

Tested on PowerShell Core 6.0

I have similar behavior with Node v8.9.0. It comes with npm 5.5.1, and when I try to downgrade to npm 4, it gives me the refusing to delete error.

same windows 10 node 8.5.0 npm 5.3.0 nvm 1.1.0

Seeing same problem

Usage:

.\updateNpm.bat <version>

Example:

.\updateNpm.bat 8.2.0

Thank you

A batch script which works fine. https://gist.github.com/nokidding/aafaf90adc80cbce54b676340817bb13

I had the same issue, and here is how I got through :

run npm install -g npm and while it is running: remove(backup) files npm.cmd and npm from c:\Program Files\nodejs\ remove(backup) .bin folder from c:\Program Files\nodejs\node_modules\npm\node_modules, then it should succeed If you have Refusing to deleteissues with any other npm module files/folders you have to just remove these and restart update process. To restart copy npm.cmd back to c:\Program Files\nodejs\ . Then once npm install -g npm is running, remove npm.cmd, otherwise you get in to Refusing to delete npm.cmd issue, you might repeat that process until npm install -g npm is happy.

To remove the files you can use this shortcut: mv npm.cmd "c:\Program Files\nodejs\node_modules\npm\node_modules" as suggested by @farnetani

my env: windows 7 x64, node 8.4, nvm 1.1.6

image

Its been 3 years since this reply, but it still works! Thank you so much

works like charm just be sure ‘set node_path=!PROGRAMFILES!\nodejs’ is pointing correct path in your case specifically incase of no standard installation(zip extract)

@jakobrosenberg Yes, you are right, I didn’t know npx behave like that, I always use it for local project packages only.

I went about it the yarn method, but this should also work:

  1. Grab npm from https://github.com/npm/cli/releases
  2. Run the following from the directory you extracted it to from its bin folder
    • node npm-cli.js i -g npm@latest
    • It may complain about files needing to be deleted, for me I had my nvm and nodejs in a root directory on my drive so the standard program file location is inapplicable to me. I nuked the npm/npx/node_modules from my nodejs folder (I’m not afraid to redownload packages and I’m working with a fresh install now anyways).
  3. It should install properly and you should be able to delete the folder you extracted and profit!

Fairly similar to this stackoverflow I wrote up. https://stackoverflow.com/questions/49748307/how-to-reinstall-npm

I also got the Refusing to delete error when trying to update npm using npm install npm@latest --global.

The npm-windows-upgrade package was unable to update as well, suggesting to reinstall Node.js, in spite of this being a fresh unzip installation.

I was able to upgrade by moving the npm and npx files, as previously suggested, using this PowerShell script:

# Locate the Node.js installation
# containing the npm and npx files that are preventing the upgrade
Get-Command node.exe | % { Split-Path $_.Source } | cd

$CurrentNpmVersion = npm --version

# Version the current npm scripts to make room for the new version:
"npm", "npm.cmd", "npx", "npx.cmd" | %{ Get-ChildItem -Filter $_ } |
  Rename-Item -NewName { "$($_.BaseName)-$CurrentNpmVersion$($_.Extension)" }

# Use the current npm command to install the new version:
Invoke-Expression "npm-$($CurrentNpmVersion).cmd install npm@latest --global"

This worked for me:

nvm use <some_other_version>
cd .../nvm/<version_to_update>
npm un npm
npm i npm@latest

@rolf-schmidiger In my experience I had to do the same renaming with npx and npx.cmd as with npm and npm.cmd.

Man. npm 5 and nvm really sucks big time (but I blame npm 5 here since 4 works perfectly fine). I’ve downgraded to npm 4.6.1 last week and just tried to give 5.4.2 another try. Looks like npm has been uninstalled while trying to install react-native-cli, a completely different package:

Manuel@Manuel-406 /cygdrive/d/htdocs/wallet
$ npm install -g react-native-cli
C:\Program Files\nodejs\npx -> C:\Program Files\nodejs\node_modules\npm\bin\npx-cli.js
npm WARN Error: EPERM: operation not permitted, scandir 'C:\Program Files\nodejs\node_modules\npm\node_modules\libnpx\node_modules\yargs\node_modules\os-locale\node_modules\execa\node_modules\cross-spawn\node_modules\shebang-command\node_modules'
npm WARN  { Error: EPERM: operation not permitted, scandir 'C:\Program Files\nodejs\node_modules\npm\node_modules\libnpx\node_modules\yargs\node_modules\os-locale\node_modules\execa\node_modules\cross-spawn\node_modules\shebang-command\node_modules'
npm WARN   stack: 'Error: EPERM: operation not permitted, scandir \'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\libnpx\\node_modules\\yargs\\node_modules\\os-locale\\node_modules\\execa\\node_modules\\cross-spawn\\node_modules\\shebang-command\\node_modules\'',
npm WARN   errno: -4048,
npm WARN   code: 'EPERM',
npm WARN   syscall: 'scandir',
npm WARN   path: 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\libnpx\\node_modules\\yargs\\node_modules\\os-locale\\node_modules\\execa\\node_modules\\cross-spawn\\node_modules\\shebang-command\\node_modules' }
npm ERR! path C:\Program Files\nodejs\npm
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall open
npm ERR! Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\npm'
npm ERR!  { Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\npm'
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\npm'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'open',
npm ERR!      path: 'C:\\Program Files\\nodejs\\npm' },
npm ERR!   stack: 'Error: EPERM: operation not permitted, open \'C:\\Program Files\\nodejs\\npm\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'C:\\Program Files\\nodejs\\npm',
npm ERR!   parent: 'v8.5.0' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Manuel\AppData\Roaming\npm-cache\_logs\2017-10-02T14_54_04_833Z-debug.log

Manuel@Manuel-406 /cygdrive/d/htdocs/_git/wallet
$ npm install -g react-native-cli
sh: npm: Kommando nicht gefunden.

npm -g install npm@5.4.2 still fails for me, same errors. [Edit] BTW, that’s starting from 5.3.0, which was installed with nvm install 8.5.0

On Fri, Sep 29, 2017 at 11:41 AM, Corey Butler notifications@github.com wrote:

@kuncevic https://github.com/kuncevic - thanks… that’s indicative the problem must be within npm 5.4.3+.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/coreybutler/nvm-windows/issues/300#issuecomment-333161774, or mute the thread https://github.com/notifications/unsubscribe-auth/AEZgRQnw_jxuz_dDZl3OsZVO_MNkHlBGks5snQ-qgaJpZM4PPcf- .

  • I am a windows 10 user.
  • I tried all the ways I can find, but they still do not work for me. 😥

And finally, I uninstall nodejs and then re-install it. Then everything is ok! This is what I did:

  1. Uninstall nodejs, and then delete the environment variable path like: C:\Program Files\nodejs
  2. Install the latest version of nodejs from here; ⚠️ you’d better not install nodejs in disk c.
  3. After installing, type node -v and npm -v in cmd. If you can see the version, congratulations! No “npm ERR” anymore! If not, add the nodejs environment variable path.

A batch script which works fine. https://gist.github.com/nokidding/aafaf90adc80cbce54b676340817bb13

This works. To use:

  1. download this as updateNpm.bat file
  2. open powershell in that same folder and run this command ./updateNpm.bat latest

That worked for me, at last.

Thank you

Another idea I’ve tried (I don’t know if anyone has already mentioned it) is to install npm directly without using npm itself. Refer to npmjs in the “Direct Download” section, and it works.

This was my fix: 1.Uninstall npm, node, remove all related directories. 2. Remove nvm bloat if any left 3. Install Volta 4. Everything works out of the box + build in rust 5. ??? 6. Profit

Feels kind of mean to offer another package as a solution… but this absolutely worked out of the box for me and I love Rust. Thanks for the info @alekslario

I just needed Step 4, i.e. Just download and fresh install Node JS. Then it worked.

Same Issue! how i solved it:

  1. Control Panel=>Uninstall a program
  2. Delete NodeJS app
  3. Delete All NodeJS Folder on program Files
  4. Fresh Install Node JS

@kuncevic Suggestion to improve your instructions:

Rather than copy files back and forth or try to move them around quickly enough while the process is running, just invoke npm’s script directly with the node command.

PowerShell:

node (Join-Path $env:NVM_SYMLINK 'node_modules\npm\lib\npm.js') install -g npm

Command Prompt:

node "%NVM_SYMLINK%\node_modules\npm\lib\npm.js" install -g npm

Then you can just remove the files once and restart the process without putting them back if needed.

You don’t have to put it into C:/Users/My Name/Roaming/Whatever you can use any directory as long as it is user-writeable.

I have all programs on D:\Programs, none of them require admin rights, including nodejs, python, cmake, JetBrains, go, OpenOffice, etc.

Then I put them all into the path environment variables and registry for current_user. Works like a charm. No crappy blackbox-installers required.

If I need to find anything, I use locate32, I don’t even browse the folders/Desktop/StartMenu. Locate32 is just way faster. Or I run them via CTRL+R, as you can set the aliases in the registry in HKCU.

The only reason to have something in C:\ProgramFiles is when you want to install a certain application for every user on the machine, which as developer in most cases, you don’t want, since having programs in systemwide path/registry might break the programs of other users, or inhibit their ability to use a different version than the version you use. Also, it comes in handy on the server - user1 can use his nodejs, user2 another nodejs, and it doesn’t bite itselfs.

By removing admin rights and keeping everything in user, you ensure that one user cannot break the the programs & settings of another user. Also you ensure your applications run without admin rights, which is something that might come in handy at times. And at worst, you can always delete and purge a user account and recrate it later.

That way I can run roughly 1’000 programs, all without a single minute spent installing. Even JetBrains IDE and PostgreSQL work that way. The only programs that I couldn’t get to work like this are MS-Office, SQL-Server and Visual-Studio. npm shouldn’t be added to this disreputable list, and all because it cannot be bothered to move a few existing files instead of overwriting them.

Anyway, I have my own nodejs-update-script now, which detects the nodes folder from the path environment variable.

@createdbyjurand recently? IIRC, PF became write-restricted for a user since XP. @MrCroft I always wondered how people could live with all the stuff buried inside PF… Space in path means quoting is always required, madness with x64-PF and x32-PF adds one iteration for search, and - the most frustrating - a totally flat software structure. I’ve >100 apps even on home PC and 50 apps even more at work. I would jump out of a window if I had to search for apps inside PF.

@createdbyjurand: WITHOUT admin rights… You don’t need admin rights to replace a bunch of file with another bunch of files… (as long as you have write access to the files/directories)

Once a year I get excited, decide to install NVM on Windows thinking “this time it will work”, but there’s always something broken… Oh well, I guess it’s back to the Node.js classic installer. I would use WSL, but unfortunately some Electron apps require you to have Node installed on the host OS.

Is this really unfixable by NVM alone? As far as I’ve read in different threads, it would also be an npm or Node issue, but isn’t there anything NVM alone could do about it? Otherwise, this issue kind of renders NVM useless on Windows. Having to delete files ourselves while in the middle of the update process or even create scripts for that or whatever workarounds some people mentioned, is not a solution. It’s hell! The only thing I’ve tried (a comment in another thread, not this one, mentioning a few steps on how to use yarn to add npm) didn’t work.

when using the script of @kufii Notice that the installation location should be replaced if you changed the path of node.js like me ,just replace the code set node_path=!PROGRAMFILES!\nodejs to set node_path=YOUR_NODE_PATH

@arfaWong 's solution worked perfectly for me (I mixed a bit with @rolf-schmidiger 's solution and renamed instead of moving)