Repository navigation
Can't upgrade npm when using symbolic links #31111
Description
Activity
@nodejs/version-management @nodejs/npm @platform-windows Would appreciate some help triaging this one.
- addednpmIssues and PRs related to the npm client dependency or the npm registry.Issues and PRs related to the npm client dependency or the npm registry.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
on Dec 27, 2019 nvm does not support windows (perhaps nvm-windows, a different project?) and there’s no trace of a version manager in the error output, so i don’t think it’s related to version management at all.
This seems like an issue with npm and symlinks on windows - have you tried filing an issue on npm’s repo directly?
nvm does not support windows (perhaps nvm-windows, a different project?) and there’s no trace of a version manager in the error output, so i don’t think it’s related to version management at all.
This seems like an issue with npm and symlinks on windows - have you tried filing an issue on npm’s repo directly?
@ljharb I'm using nvm-windows. But I don't think that's the issue. To me, seems like something going wrong with the symlinks. The recent commit which I have referenced was supposed to fix this issue, but it looks broken. It deletes npm.exe basically and after that, there's no update as that file is required from what I understand. So I have to reinstall Node.js to solve this.
Nope, I didn't file an issue on npm repo yet. I saw the PR here, so thought I'll mention here.
The PR here just updates the default installed npm; the problem would have to be fixed in npm itself. Filing an issue there will likely have more effect :-)
The PR here just updates the default installed npm; the problem would have to be fixed in npm itself. Filing an issue there will likely have more effect :-)
Thanks for the info. I shall make the issue in the npm repo.
Reacted by Jordan HarbandThat's a permissions issue. Windows requires administrative privileges to execute anything within or write to the
C:\Program Filesdirectory. In some corporate environments, it also requires additional elevation (depending on how Active Directory GPO's are setup). npx may attempt to write new modules to the directory upon first execution. When upgrading npm, the typical operation is to remove the old version before writing the new version, so it's trying to write to a protected directory without appropriate permissions.I'll also point out that the output looks like it's coming from a bash shell. I recommend first trying this in a normal terminal/powershell and assuring you have appropriate permissions. That should at least give you a starting point to rule out permission problems (as opposed to shell issues or npm issues).
Reacted by Scott SantucciThat's a permissions issue. Windows requires administrative privileges to execute anything within or write to the
C:\Program Filesdirectory. In some corporate environments, it also requires additional elevation (depending on how Active Directory GPO's are setup). npx may attempt to write new modules to the directory upon first execution. When upgrading npm, the typical operation is to remove the old version before writing the new version, so it's trying to write to a protected directory without appropriate permissions.I'll also point out that the output looks like it's coming from a bash shell. I recommend first trying this in a normal terminal/powershell and assuring you have appropriate permissions. That should at least give you a starting point to rule out permission problems (as opposed to shell issues or npm issues).
@coreybutler Yes you're right, I was using Git Bash at that time, but the output was same for all. I am using my personal laptop for this.
I reinstalled Node.js v12.11.1 with npm v6.11.3 Here's output for
npm update -gon CMD, Git Bash and Powershell for both admin and non-admin modes:Either this:
npm ERR! code EEXIST npm ERR! path C:\Program Files\nodejs\npx.cmd 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.Or this:
npm ERR! code EEXIST npm ERR! path C:\Program Files\nodejs\npm.cmd npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link npm ERR! File exists: C:\Program Files\nodejs\npm.cmd npm ERR! Move it away, and try again.@aravindvnair99 Did you reinstall with NVM4W or manually using the official msi? If you didn't uninstall NVM4W or an old version prior to the new installation, you'll likely run into npm version conflicts.
See nvm-windows/nvm#300 (comment), which addresses the issue you're seeing. Like the error states, the workaround is to manually remove the files.... basically give npm a clear slate & start again.
@aravindvnair99 Did you reinstall with NVM4W or manually using the official msi? If you didn't uninstall NVM4W or an old version prior to the new installation, you'll likely run into npm version conflicts.
See coreybutler/nvm-windows#300 (comment), which addresses the issue you're seeing. Like the error states, the workaround is to manually remove the files.... basically give npm a clear slate & start again.
@coreybutler Thanks for the quick response. I didn't reinstall NVM4W, I only uninstalled Node 12.11.1 via
nvm uninstall 12.11.1and then installed it again vianvm install 12.11.1. I tried for different versions of Node.js and npm combinations and ended up with the same result. I also did try removing the files stated in the error.nvm-windows/nvm#300 (comment) is what I have been doing for almost a year now. That works fine. But I'm still wondering why I am unable to update directly. It works fine when I'm using the official MSI, but not when using NVM4W. So, I thought it's something to do with the symlinks.
My Node.js and npm works fine, just that
npm update -gornpm i -g npmthrows me the errors stated above. I have also tried it on a fresh install of Windows.@targos The issue still persists.
Sorry, I forgot to leave a message. You should open an issue in the npm/cli repository. npm is not developed here.
#30904 breaks dynamic links when using nvm.
npm install -g npmoutputs:C:\Program Files\nodejs\npx -> C:\Program Files\nodejs\node_modules\npm\bin\npx-cli.js
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Program Files\nodejs\npm
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\npm'
npm ERR! [OperationalError: EPERM: operation not permitted, open 'C:\Program Files\nodejs\npm'] {
npm ERR! cause: [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! 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! }
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.
After which,
npmoutputs:bash: /c/Program Files/nodejs/npm: No such file or directory
And
npm.exehas vanished:Related:
npm/bin-links#12
npm/gentle-fs#7
npm/cli@320ac9a