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.
[ ] Windows Server 2016
[ ] My Windows installation is non-English.
npm i -g npm@latest should install latest npm version
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.
run as an administrator npm i -g npm@latest
Same problem here.
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 delete
issues 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
Seeing same problem
same
windows 10
node 8.5.0
npm 5.3.0
nvm 1.1.0
@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.
So much for production. Good luck doing in a script.
They should rename continuous integration to continuous intebreaktion
@19majkel94 Couldn't get it working with your method... any other ideas which I could script?
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.
I wish I could help, but I have an observation... I think that the issues are related to the shortcut to "C:/Program Files/nodejs
". Perhaps if a junction were used instead of a shortcut? Windows can't tell the difference between a 'real' directory and a junction. So, it would look like node was really and truly installed in the default directory. No more 'operating' in a directory outside of the resolved directory.
https://docs.microsoft.com/en-us/sysinternals/downloads/junction
BTW, using a junction should future proof nvm4w against any future changes to npm's behavior.
@wayne-oscme
Have you read the readme?
The second option is to use a symlink. This concept requires putting the symlink in the system PATH, then updating its target to the node installation directory you want to use. This is a straightforward approach, and seems to be what people recommend.... until they realize just how much of a pain symlinks are on Windows. This is why it hasn't happened before.
In order to create/modify a symlink, you must be running as an admin, and you must get around Windows UAC (that annoying prompt). Luckily, this is a challenge I already solved with some helper scripts in node-windows. As a result, NVM for Windows maintains a single symlink that is put in the system PATH during installation only. Switching to different versions of node is a matter of switching the symlink target. As a result, this utility does not require you to run nvm use x.x.x every time you open a console window. When you do run nvm use x.x.x, the active version of node is automatically updated across all open console windows. It also persists between system reboots, so you only need to use nvm when you want to make a change.
@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.
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)
Okay, I guess I should try before selling. I replaced the shortcut with a
junction, and got the same exact issue. Thought I had something there.
Sorry to waste your time.
On Wed, Sep 27, 2017 at 9:38 AM, Corey Butler notifications@github.com
wrote:
This has nothing to do with junctions/hard links/symlinks. @kuncevic
https://github.com/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)
—
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-332523342,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEZgRbY_GVys0bfnD_kaM_PYl6QUmZKDks5smk_PgaJpZM4PPcf-
.
Just updated 5.4.1 → 5.4.2
with no issues.
c:\>npm install npm -g
C:\Program Files\nodejs\npx -> C:\Program Files\nodejs\node_modules\npm\bin\npx-cli.js
C:\Program Files\nodejs\npm -> C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
+ [email protected]
removed 1 package and updated 2 packages in 12.125s
@kuncevic - thanks... that's indicative the problem must be within npm 5.4.3+.
npm -g install [email protected] 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-
.
For me it fails from Node 8.4.0 and up. It installs NPM 5.3.0, and then won't allow me to upgrade it.
Older Node versions (I have 4.8.4) allow NPM to update normally.
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.
ubuntu
: 16.04.2 LTS
nodejs
: 8.6.0
npm
: 5.3.0
npm i -g npm@latest
/home/user/.npm-global/bin/npm -> /home/user/.npm-global/lib/node_modules/npm/bin/npm-cli.js
/home/user/.npm-global/bin/npx -> /home/user/.npm-global/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
added 68 packages, removed 164 packages and updated 14 packages in 14.307s
npm -v
still prints 5.3.0
and it's not updated?
@yavorski - this is nvm for Windows. I think you want nvm for *nix.
I have confirmed this issue is sandboxing within npm 5.x.x. Prior editions of npm did not have this. Unfortunately, the fix is non-trivial, and judging by @yavorski's experience, it's not specific to this project.
Yep no nvm in my case. Linux + Nodejs from nodesource.
Having same issue here...
npm version 5.4.2
node version 8.7.0
window 10
I have the same problem。
Windows 10
mv npm.cmd "c:\Program Files\nodejs\node_modules\npm\"
and after
npm i -g npm@latest
Solved to me!
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.
I tried to manually fix this, by pulling npm from the official zip file, and I got this error:
I suspect this error is occurring silently and corrupting the install. When I install to C:\nvm
, I don't get this error and everything works as expected.
@RichardMisiak did you try moving the nvm
install to a path closer to C:\
? Like C:\nvm
? It cleared up the issue for me.
With the latest node 9.1
that bringing the latest npm 5.5.1
by default there is even more "fun" https://github.com/npm/npm/issues/19019, saying with the next npm release it might be fixed.
My solution is NOT very elegant but it works. Here it is.
After running npm install [email protected] -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:
npm install -g yarn
yarn global bin
, and add the folder that is displayed to the PATH env variable of Windowsnpm install [email protected] -g
run: d:\node\
in my case) and:npm
to npm.original
(or just delete it)npm.cmd
to npm.cmd.original
(or just delete it)yarn global add [email protected]
npm install [email protected] -g
(this will install npm using the npm version located on the yarn global bin
folder)yarn global remove npm
(to delete the npm version installed by yarn, and keep only the version installed by npm itself)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
@rolf-schmidiger In my experience I had to do the same renaming with npx and npx.cmd as with npm and npm.cmd.
Deliciously simple and effective, @rolf-schmidiger. Thank you.
@coreybutler, any idea on a solution? Just curious. No pressure.
None of the solutions listed here worked for me, and in the end it was quicker to use nvmw uninstall
to delete the Node installation and then nvmw install
to reinstall it.
Isn't nvmw
a completely different tool?
@thegreatco Oops! You're right. Interesting that the same issue occurs on both, though!
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 just installed everything for the first time, so none of the above suggestions seem to apply to me. I keep getting this when trying to execute npx create-react-app
:
npx : The term 'npx' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
Windows 10 Pro, build 1703, fresh re-install about 2 weeks ago with Developer Mode enabled
Node version 9.4.0
npm 5.6.0
The install instructions were a little confusing (there are multiple files to download, what is that no-install file for?) but I finally figured out that you have to turn nvm 'on' and then issue the 'use' command, (confused me because I'm not using a separate package manager so I thought that part didn't apply) but then I'm still getting the above error.
I tried every possible thing. I uninstalled nvm and installed a different version, I checked the environment path, I ran out of ideas. I finally just did npm install -g npx
and that seems to be working. Screw it.
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.
I got same problem (windows 10 environment) when trying to upgrade my node 8.8.0 with npm 5.5.1 to node 9.8.0 but installation of node 9.8.0 does not update my npm from 5.5.1 to latest. After it I try to npm i -g npm
and get error:
C:\Repository\myproject>npm i -g npm
npm WARN npm npm does not support Node.js v9.8.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
WARNING: You are likely using a version of node-tar or npm that is incompatible with this version of Node.js.
Please use either the version of npm that is bundled with Node.js, or a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is compatible with Node.js 9 and above.
npm[19860]: src\node_zlib.cc:436: Assertion `args.Length() == 7 && "init(windowBits, level, memLevel, strategy, writeResult, writeCallback," " dictionary)"' failed.
1: node::DecodeWrite
2: node::DecodeWrite
3: uv_loop_size
4: v8::internal::wasm::SignatureMap::Find
5: v8::internal::Builtins::CallableFor
6: v8::internal::Builtins::CallableFor
7: v8::internal::Builtins::CallableFor
8: 000003BEBC8843C1
@arfaWong 's solution worked perfectly for me (I mixed a bit with @rolf-schmidiger 's solution and renamed instead of moving)
It is very simple.. If you are on windows kindly check https://github.com/felixrieseberg/npm-windows-upgrade
If you want to do it manually kindly check the documentation https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows
I threw together a PowerShell script to automate @arfaWong 's solution: https://gist.github.com/noahleigh/ba34e18b3e0bc4a6a4e93ed7a480536e
Tested on PowerShell Core 6.0
@rvkmar nope, no luck https://github.com/felixrieseberg/npm-windows-upgrade/issues/124
Same problem with
node-v8.6.0-win-x64
node-v9.9.0-win-x64
and if you rename the file or move them, it will fail with unable to create folder, please re-run as administrator. Appart from the fact that I don't have admin rights on this machine, it is doubtful that this would change anything, as the current user has mkdir permissions in that folder...
When will that ever get fixed ?
thanks for your solution @ayvarot
I used nvm 1.1.15 and node 9.8.0
Updated from 5.6.0 to 5.8.0
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)
@arfaWong That worked... Although not the ideal one...
Will wait for npm team to fix it...
.
Faced this with npm 5.6.0
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
@arfaWong solution worked like a charm, thank you!
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.
This seems now triggered by installation of Nodejs version 10.0.0 using nvm.
@arfaWong The only solution that worked guys. Try this out.
@rolf-schmidiger worked for me! thank you
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
This worked for me:
nvm use <some_other_version>
cd .../nvm/<version_to_update>
npm un npm
npm i npm@latest
use yarn instead of npm it self, try yarn global add npm@latest
, try to upgrade yarn if this fails.
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"
Hi @awarberg I tried your script but I get this error. I tried with yarn as well, no luck... stupid Windows! 💢
.\update_node.ps1
npm ERR! path C:\Program Files\nodejs\node_modules\npm\node_modules\worker-farm\node_modules\.bin\errno
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Program Files\nodejs\node_modules\npm\node_modules\worker-farm\node_modules\.bin\errno: is outside C:\Program Files\nodejs\node_modules\npm\node_modules\worker-farm\node_modules\errno and not a link
npm ERR! File exists: C:\Program Files\nodejs\node_modules\npm\node_modules\worker-farm\node_modules\.bin\errno
npm ERR! Move it away, and try again.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\vitom\AppData\Roaming\npm-cache\_logs\2018-05-11T12_55_55_902Z-debug.log
@lamuertepeluda sorry to hear you still can't upgrade. The file mentioned ...\node_modules\.bin\errno
was not mentioned previously. This could be a corrupted installation due to multiple upgrade attempts. May be a good time to reinstall it, as npm-windows-upgrade suggests.
As for "stupid Windows" I don't agree. More likely, NPM was designed for Linux first, and Windows support was bolted on later, as an after thought. I see this regularly in other NPM packages as well. Typical problems are difficulty to install and requires manual and undocumented steps to ensure software prerequisites. Another common problem is case sensitive file system pathing.
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
)
)
)
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
@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)
@kufii's updated version works better for me than having the desired number hardcoded into the script.
@kufii @arfaWong
Thank you!!
@johnmcase Worked liked a charm, bookmarking.
Only one issue with this script found: when I selected to install 5.6
it successfully installed 5.6.0
and been rolling back as "5.6" differs from "5.6.0"...
Thank You for the script though!
Had the same issue again recently with nvm version 1.1.7
The solution of @arfaWong and @ayvarot worked the last time. But this time Idkw the npm folder wasn´t found. So I recommend not to delete the npm2 folder just in case.
I just spent nearly two days debugging errors caused by this problem and tried nearly every fix to upgrade my NPM from 5.6.0 to 6.1.0. @arfaWong's fix worked for me without any further issues. Thank you!
@arfaWong Works!!
I went about it the yarn method, but this should also work:
bin
foldernode npm-cli.js i -g npm@latest
Fairly similar to this stackoverflow I wrote up.
https://stackoverflow.com/questions/49748307/how-to-reinstall-npm
@ayvarot Thanks very much!!!!!!!! Your advice work for me on Windows 10.
Worked for me with just renaming %Node%\npm.cmd
, %Node%\npm
and %Node%\npx.cmd
, no directory renaming was required.
@peternann's suggested solution here works, too.
https://github.com/coreybutler/nvm-windows/issues/389
For some reason the script above wasn't working for me and I was simply too tired resolving this to find out why.
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
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
@kraihn solution does not work now with the latest yarn unless you add yarn bin in to the path:
path
by yarn global bin
path
in to your path
variableOnce 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.
@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.
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.
Maybe somebody should test the npm updater WITHOUT ADMIN RIGHTS...
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)
@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)
@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)
I know. But, Program Files folder on Windows 10 has specific rights access. That is why lots of apps install itself lately in Roaming or Local folders. Even Visual Studio Code has two separate installs. One for Local and one for Program Files. One way to workaround this is to change in nvm nodejs folder location. Second, change Folder Security options but that makes this folder unsecure. What I wrote, what @19majkel94 wrote, is a solution to fix npm update just the way it is, using standard nvm install with default settings for people who just want to fix the problem without getting into more and more system or configuration changes. Because even if you change folder or access rights, you still have to do all the steps I listed, and the only change will be using the console without admin rights.
@createdbyjurand: Just saying, we run node in a corporate environment, and as developers, we have no admin rights. If an npm-update or a script therein requires admin rights, that breaks our dev-environment, and then we can't install any node packages, and then we can't work.
@createdbyjurand what do you need admin rights for?
@createdbyjurand what do you need admin rights for?
Good point, I don't, because I've just deleted files that were creating conflicts 👍
Oh I see. I never imagined having NPM installed in PF, for me is rather weird. I'd say those who do it are the reasons of their troubles :).
Oh I see. I never imagined having NPM installed in PF, for me is rather weird. I'd say those who do it are the reasons of their troubles :).
Recently yes. Microsoft changed access rights for Program Files folder. That is why a lot of software is moving now towards Roaming or Local folder install directory. And this is why not so long ago everything was working fine with npm, and now suddenly we get this:
$ npm i -g npm@latest
C:\Program Files\nodejs\npx -> C:\Program Files\nodejs\node_modules\npm\bin\npx-cli.js
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:
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!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\fehTH4RTH\AppData\Roaming\npm-cache\_logs\2019-03-22T14_28_26_153Z-debug.log
Oh I see. I never imagined having NPM installed in PF, for me is rather weird. I'd say those who do it are the reasons of their troubles :)
@Fr0sT-Brutal well, for the sake of organization, I do it as well. If I already have a system folder designated for applications (Program Files), whenever I install anything - I install it in the "Program Files" folder. Especially not to pollute the drive's root folder with random folders like "nodejs" or "nvm" and also not to get to long paths, like "c:/Users/My Name/Roaming/ApplicationData/whatever", I just prefer "c:/Program Files/whatever".
Nonetheless, although it would have really bugged me to work like that (have nvm|node in a place outside program files), still... I've at least tried and I've installed it in c:/nvm (as for node versions, I've tried both c:/node and as a subfolder of nvm: c:/nvm/node something like that). But the issue persisted, npm still couldn't be updated by running npm i -g npm
. Thank God, because I wouldn't want to live with things installed outside of the Program Files folder. Of course I finally gave up and still using 1 version of node at all times, installed using the default node installer for Windows from nodejs.org
@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.
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.
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?
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
I just renamed these files to "1"
npm1.cmd, npm1, npx1, npx1.cmdand ran:
"npm1 update -g"It looks like it worked fine, any thoughts?
It worked for me too, but I had to delete the folder
nvmv10.15.3node_modulesnpmnode_modules.bin
because the error pointing to this folder still appeared.
Thank you!
Hey guys i have made a package for update the local npm version of Program Filesnodejs
Checkout
npm install -g npm-win-upgrade
npm-win-upgrade
Not sure if compatible with NVM at all but it use process.execPath to locate node.exe folder, so it should do.
@dolpsdw I get the following error when running npm-win-upgrade
:
Npm instaled as Global package: uninstalling...
(node:10192) UnhandledPromiseRejectionWarning: Error: Command failed: npm uninstall npm -g
npm ERR! path C:\Program Files\nodejs\npx.cmd
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and
not a link
npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
npm ERR! Move it away, and try again.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\sjodle\AppData\Roaming\npm-cache\_logs\2019-04-23T17_42_11_305Z-debug.log
at ChildProcess.exithandler (child_process.js:281:12)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:915:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:10192) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (
rejection id: 1)
(node:10192) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejec
tions that are not handled will terminate the Node.js process with a non-zero exit code.
Hi @sodle,
The first error (node:10192 Command failed: npm uninstall npm -g): it happens because npm detected as global instaled in the %appdata%npm folder, but this may be rest of and old node cache. This could be fixed with an npm list -g detection.
About the second error to me that error of 'Refusing to delete'... sounds like the Admin privileges where no authorized in the process. (UAC promp was denied?)
Try to execute the script and accept the Admin privilege scalation, and if that doesnt fix it please Tell me your node version of Origin to reproduce the bug.
@dolpsdw I'm pretty sure those are both part of the same error - npm is refusing to delete the file because it's misplaced or something.
At any rate, I no longer have the machine that the error occurred on. I'll let you know if I encounter the same issues on its replacement.
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.
@dolpsdw npm-win-upgrade
failed with the same errors as npm install -g npm
.
There is another package npm-windows-upgrade
, which also fails, but doesn't say why (I assume it's the same).
@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
)
Read through this thread; in the end, I had the best luck uninstalling and reinstalling node.js using add/remove programs.
Problem was being fixed for me like a year ago by switching on mac ;)
@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 ;)
:rofl:
@kuncevic, @Fr0sT-Brutal:
And by giving up your freedom of choice when it comes to hardware.
Not a good trade-off at all.
Also, you're surrendering your control over the software that runs on your computer.
If you need to switch somewhere, switch to Linux - that's the much better choice, for server stuff anyway.
https://blog.npmjs.org/post/189618601100/binary-planting-with-the-npm-cli
I dropped nvm for windows. After 2 years, it still doesn't work properly even with the latest node version
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.
I just renamed these files to "1"
npm1.cmd, npm1, npx1, npx1.cmdand 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
.
@coreybutler I'm not totally convinced of that. npm-windows-upgrade did not work for me. Then after I manually cleared out the top level scripts (the same ones others are renaming here, and also the npx ones), node (Join-Path $env:NVM_SYMLINK 'node_modules\npm\lib\npm.js') install -g npm
worked initially, and npm install -g npm
worked for a later update without manual intervention. It seems like the initial npm install is broken somehow.
Even if that is somehow npm's fault for having a broken installer or something rather than nvm's, one step nvm could take to alleviate the problem is to clear out these scripts itself and invoke an update immediately when creating the initial version environment. Or at least it could provide an option or command to do so.
@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.
@bladeoflight16 I tried but got this error.
C:\Users\woonk>node %NVM_SYMLINK%\node_modules\npm\lib\npm.js install -g npm
internal/modules/cjs/loader.js:796
throw err;
^
Error: Cannot find module 'C:\Program'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
@mattdamon108 Sorry. You need to quote the path in cmd if it has spaces. I updated the post. Thanks.
Was getting this Error on Windows and wanted to revert to an older npm for a project and in a very mild manner I just went to the already formed symlink location of npm command and renamed the npm folder in node_modules to its own version name and then downloaded the version I needed and created a folder called npm
and dumped the downloaded contents there which worked!
@coreybutler your suggestion of creating a symlink did not work since windows complained that a symlink is already existing. Also in windows it is a pain to quickly edit a symlink. Also I needed to switch between the 2 versions of npm regularly. Hence I did this.
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 thenpm
update.No need to use
npm-windows-upgrade
.
@xmedeko @chidveer Maybe I'm missing something here, but isn't npx npm-windows-upgrade
more straight forward than manually renaming files before running npm update
?
@jakobrosenberg npm-windows-upgrade
has not worked for me. Maybe I did something wrong, maybe I did attempted upgrade, or whatever. IMO one file rename is simpler than to study, why npm-windows-upgrade
is not working and how to fix it.
Note: it's recommended to use npm-windows-upgrade
globally, so you run it as npm-windows-upgrade
, not npx npm-windows-upgrade
.
@xmedeko wouldn't npx npm-windows-upgrade
run globally unless you're inside a node project with a local installation of npm-windows-upgrade
?
@jakobrosenberg Yes, you are right, I didn't know npx
behave like that, I always use it for local project packages only.
A batch script which works fine.
https://gist.github.com/nokidding/aafaf90adc80cbce54b676340817bb13
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)
Same Issue!
how i solved it:
I just needed Step 4, i.e. Just download and fresh install Node JS.
Then it worked.
Reinstalling the node version works fine, but since this is an issue associated with nvm
, why not use the power of nvm
to fix the problem? For me, instead of going through add/remove programs, it was way quicker/simpler to keep it all in the command line. For example:
nvm uninstall VERSION
nvm install VERSION
After that, close and re-open the shell. Quick and easy (now that you know, at least). 😄
If you have any issues (e.g. nvm
indicates that the version is already installed), then check to see if the folder associated with that version still exists (e.g. %NVM_HOME%\VERSION
) and that the file node.exe
isn't still there. If it is still there, make sure you didn't already have any apps potentially running node (e.g. in my case my IDE was running it, so I closed that and was able to completely remove).
EDIT: ⚠️ I suppose this simple solution comes with one important side effect: It will remove your globally installed packages... hmm... may still be simpler to manually reinstall those. Be warned! ⚠️
This script works perfect: https://github.com/coreybutler/nvm-windows/issues/300#issuecomment-606682441
https://gist.github.com/nokidding/aafaf90adc80cbce54b676340817bb13
Thank you!
Most helpful comment
I just remove the
npm
andnpm.cmd
files from the nodejs location, move dirnode_modules/npm
from the nodejs location to another location, and runnode npm-cli.js i -g npm@latest
insidebin
dir in the moved folder.