New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update npm (node 8.4.0) #300

Open
t0lkman opened this Issue Sep 7, 2017 · 76 comments

Comments

Projects
None yet
@t0lkman

t0lkman commented Sep 7, 2017

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

@manuelbieh

This comment has been minimized.

Show comment
Hide comment
@manuelbieh

manuelbieh Sep 7, 2017

Same problem here.

manuelbieh commented Sep 7, 2017

Same problem here.

@kuncevic

This comment has been minimized.

Show comment
Hide comment
@kuncevic

kuncevic Sep 10, 2017

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

kuncevic commented Sep 10, 2017

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

@alexgorbatchev

This comment has been minimized.

Show comment
Hide comment
@alexgorbatchev

alexgorbatchev Sep 16, 2017

Seeing same problem

alexgorbatchev commented Sep 16, 2017

Seeing same problem

@cannap

This comment has been minimized.

Show comment
Hide comment
@cannap

cannap Sep 17, 2017

same
windows 10
node 8.5.0
npm 5.3.0
nvm 1.1.0

cannap commented Sep 17, 2017

same
windows 10
node 8.5.0
npm 5.3.0
nvm 1.1.0

@19majkel94

This comment has been minimized.

Show comment
Hide comment
@19majkel94

19majkel94 Sep 22, 2017

@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.

19majkel94 commented Sep 22, 2017

@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.

@wayofthefuture

This comment has been minimized.

Show comment
Hide comment
@wayofthefuture

wayofthefuture Sep 23, 2017

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

wayofthefuture commented Sep 23, 2017

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

@wayofthefuture

This comment has been minimized.

Show comment
Hide comment
@wayofthefuture

wayofthefuture Sep 23, 2017

They should rename continuous integration to continuous intebreaktion

wayofthefuture commented Sep 23, 2017

They should rename continuous integration to continuous intebreaktion

@wayofthefuture

This comment has been minimized.

Show comment
Hide comment
@wayofthefuture

wayofthefuture Sep 25, 2017

@19majkel94 Couldn't get it working with your method... any other ideas which I could script?

wayofthefuture commented Sep 25, 2017

@19majkel94 Couldn't get it working with your method... any other ideas which I could script?

@coreybutler

This comment has been minimized.

Show comment
Hide comment
@coreybutler

coreybutler Sep 25, 2017

Owner

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.

Owner

coreybutler commented Sep 25, 2017

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.

@wayne-oscme

This comment has been minimized.

Show comment
Hide comment
@wayne-oscme

wayne-oscme Sep 26, 2017

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

wayne-oscme commented Sep 26, 2017

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

@wayne-oscme

This comment has been minimized.

Show comment
Hide comment
@wayne-oscme

wayne-oscme Sep 26, 2017

BTW, using a junction should future proof nvm4w against any future changes to npm's behavior.

wayne-oscme commented Sep 26, 2017

BTW, using a junction should future proof nvm4w against any future changes to npm's behavior.

@19majkel94

This comment has been minimized.

Show comment
Hide comment
@19majkel94

19majkel94 Sep 26, 2017

@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 commented Sep 26, 2017

@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.

@wayne-oscme

This comment has been minimized.

Show comment
Hide comment
@wayne-oscme

wayne-oscme Sep 26, 2017

@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.

wayne-oscme commented Sep 26, 2017

@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.

@coreybutler

This comment has been minimized.

Show comment
Hide comment
@coreybutler

coreybutler Sep 27, 2017

Owner

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)
Owner

coreybutler commented Sep 27, 2017

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)
@wayne-oscme

This comment has been minimized.

Show comment
Hide comment
@wayne-oscme

wayne-oscme Sep 28, 2017

wayne-oscme commented Sep 28, 2017

@kuncevic

This comment has been minimized.

Show comment
Hide comment
@kuncevic

kuncevic Sep 29, 2017

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
+ npm@5.4.2
removed 1 package and updated 2 packages in 12.125s

kuncevic commented Sep 29, 2017

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
+ npm@5.4.2
removed 1 package and updated 2 packages in 12.125s
@coreybutler

This comment has been minimized.

Show comment
Hide comment
@coreybutler

coreybutler Sep 29, 2017

Owner

@kuncevic - thanks... that's indicative the problem must be within npm 5.4.3+.

Owner

coreybutler commented Sep 29, 2017

@kuncevic - thanks... that's indicative the problem must be within npm 5.4.3+.

@wayne-oscme

This comment has been minimized.

Show comment
Hide comment
@wayne-oscme

wayne-oscme Sep 29, 2017

wayne-oscme commented Sep 29, 2017

@doug2k1

This comment has been minimized.

Show comment
Hide comment
@doug2k1

doug2k1 Sep 29, 2017

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.

doug2k1 commented Sep 29, 2017

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.

@manuelbieh

This comment has been minimized.

Show comment
Hide comment
@manuelbieh

manuelbieh Oct 2, 2017

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.

manuelbieh commented Oct 2, 2017

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.
@yavorski

This comment has been minimized.

Show comment
Hide comment
@yavorski

yavorski Oct 4, 2017

  • 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
+ npm@5.4.2
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 commented Oct 4, 2017

  • 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
+ npm@5.4.2
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?

@coreybutler

This comment has been minimized.

Show comment
Hide comment
@coreybutler

coreybutler Oct 4, 2017

Owner

@yavorski - this is nvm for Windows. I think you want nvm for *nix.

Owner

coreybutler commented Oct 4, 2017

@yavorski - this is nvm for Windows. I think you want nvm for *nix.

@coreybutler

This comment has been minimized.

Show comment
Hide comment
@coreybutler

coreybutler Oct 4, 2017

Owner

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.

Owner

coreybutler commented Oct 4, 2017

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.

@yavorski

This comment has been minimized.

Show comment
Hide comment
@yavorski

yavorski Oct 5, 2017

Yep no nvm in my case. Linux + Nodejs from nodesource.

yavorski commented Oct 5, 2017

Yep no nvm in my case. Linux + Nodejs from nodesource.

@larryboymi

This comment has been minimized.

Show comment
Hide comment
@larryboymi

larryboymi Oct 20, 2017

Having same issue here...

larryboymi commented Oct 20, 2017

Having same issue here...

@stgaup

This comment has been minimized.

Show comment
Hide comment
@stgaup

stgaup Apr 23, 2018

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.

stgaup commented Apr 23, 2018

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.

@BurtHarris

This comment has been minimized.

Show comment
Hide comment
@BurtHarris

BurtHarris Apr 26, 2018

This seems now triggered by installation of Nodejs version 10.0.0 using nvm.

BurtHarris commented Apr 26, 2018

This seems now triggered by installation of Nodejs version 10.0.0 using nvm.

@nevinm

This comment has been minimized.

Show comment
Hide comment
@nevinm

nevinm Apr 27, 2018

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

nevinm commented Apr 27, 2018

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

@RickieWoo

This comment has been minimized.

Show comment
Hide comment
@RickieWoo

RickieWoo May 3, 2018

@rolf-schmidiger worked for me! thank you

RickieWoo commented May 3, 2018

@rolf-schmidiger worked for me! thank you

@kraihn

This comment has been minimized.

Show comment
Hide comment
@kraihn

kraihn May 3, 2018

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

kraihn commented May 3, 2018

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
@xmbhasin

This comment has been minimized.

Show comment
Hide comment
@xmbhasin

xmbhasin May 3, 2018

This worked for me:

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

xmbhasin commented May 3, 2018

This worked for me:

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

This comment has been minimized.

Show comment
Hide comment
@hwangzhiming

hwangzhiming May 7, 2018

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

hwangzhiming commented May 7, 2018

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

@awarberg

This comment has been minimized.

Show comment
Hide comment
@awarberg

awarberg May 10, 2018

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"

awarberg commented May 10, 2018

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"
@lamuertepeluda

This comment has been minimized.

Show comment
Hide comment
@lamuertepeluda

lamuertepeluda May 11, 2018

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 commented May 11, 2018

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
@awarberg

This comment has been minimized.

Show comment
Hide comment
@awarberg

awarberg May 11, 2018

@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.

awarberg commented May 11, 2018

@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.

@kufii

This comment has been minimized.

Show comment
Hide comment
@kufii

kufii May 18, 2018

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
		)
	)
)

kufii commented May 18, 2018

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
		)
	)
)
@johnmcase

This comment has been minimized.

Show comment
Hide comment
@johnmcase

johnmcase May 18, 2018

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 commented May 18, 2018

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

@kufii

This comment has been minimized.

Show comment
Hide comment
@kufii

kufii May 18, 2018

@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 commented May 18, 2018

@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)

@BurtHarris

This comment has been minimized.

Show comment
Hide comment
@BurtHarris

BurtHarris May 19, 2018

@kufii's updated version works better for me than having the desired number hardcoded into the script.

BurtHarris commented May 19, 2018

@kufii's updated version works better for me than having the desired number hardcoded into the script.

@SOSANA

This comment has been minimized.

Show comment
Hide comment
@SOSANA

SOSANA commented May 20, 2018

@kufii @arfaWong

Thank you!!
notworthy

ramijarrar added a commit to fractal-code/meteor-azure-server-init that referenced this issue Jun 4, 2018

@kamranayub

This comment has been minimized.

Show comment
Hide comment
@kamranayub

kamranayub Jun 5, 2018

@johnmcase Worked liked a charm, bookmarking.

kamranayub commented Jun 5, 2018

@johnmcase Worked liked a charm, bookmarking.

ramijarrar added a commit to fractal-code/meteor-azure-server-init that referenced this issue Jun 5, 2018

@mkasprz

This comment has been minimized.

Show comment
Hide comment
@mkasprz

mkasprz Aug 1, 2018

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!

mkasprz commented Aug 1, 2018

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!

@mazyvan

This comment has been minimized.

Show comment
Hide comment
@mazyvan

mazyvan Aug 8, 2018

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.

mazyvan commented Aug 8, 2018

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.

@MendelBak

This comment has been minimized.

Show comment
Hide comment
@MendelBak

MendelBak Aug 9, 2018

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!

MendelBak commented Aug 9, 2018

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!

@apillai-incomm

This comment has been minimized.

Show comment
Hide comment
@apillai-incomm

apillai-incomm commented Aug 27, 2018

@arfaWong Works!!

@ctsstc

This comment has been minimized.

Show comment
Hide comment
@ctsstc

ctsstc Sep 2, 2018

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

ctsstc commented Sep 2, 2018

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

@DmitriyWebDev

This comment has been minimized.

Show comment
Hide comment
@DmitriyWebDev

DmitriyWebDev Sep 6, 2018

@ayvarot Thanks very much!!!!!!!! Your advice work for me on Windows 10.

DmitriyWebDev commented Sep 6, 2018

@ayvarot Thanks very much!!!!!!!! Your advice work for me on Windows 10.

@coreybutler coreybutler referenced this issue Sep 19, 2018

Closed

nvm with node 8.12.0 won't install npm 6.4.1 #393

0 of 22 tasks complete
@Fr0sT-Brutal

This comment has been minimized.

Show comment
Hide comment
@Fr0sT-Brutal

Fr0sT-Brutal Sep 25, 2018

Worked for me with just renaming %Node%\npm.cmd, %Node%\npm and %Node%\npx.cmd, no directory renaming was required.

Fr0sT-Brutal commented Sep 25, 2018

Worked for me with just renaming %Node%\npm.cmd, %Node%\npm and %Node%\npx.cmd, no directory renaming was required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment