Skip to content
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

Can't upgrade npm when using symbolic links #31111

Closed
aravindvnair99 opened this issue Dec 27, 2019 · 11 comments
Closed

Can't upgrade npm when using symbolic links #31111

aravindvnair99 opened this issue Dec 27, 2019 · 11 comments
Labels
npm Issues and PRs related to the npm client dependency or the npm registry. windows Issues and PRs related to the Windows platform.

Comments

@aravindvnair99
Copy link

  • Version: Version independent
  • Platform: Windows 10 x64

#30904 breaks dynamic links when using nvm.

npm install -g npm outputs:

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, npm outputs:

bash: /c/Program Files/nodejs/npm: No such file or directory

And npm.exe has vanished:

image

Related:

npm/bin-links#12
npm/gentle-fs#7
npm/cli@320ac9a

@Trott
Copy link
Member

Trott commented Dec 27, 2019

@nodejs/version-management @nodejs/npm @platform-windows Would appreciate some help triaging this one.

@Trott Trott added npm Issues and PRs related to the npm client dependency or the npm registry. windows Issues and PRs related to the Windows platform. labels Dec 27, 2019
@ljharb
Copy link
Member

ljharb commented 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?

@aravindvnair99
Copy link
Author

aravindvnair99 commented 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?

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

@ljharb
Copy link
Member

ljharb commented Dec 27, 2019

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

@aravindvnair99
Copy link
Author

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.

@coreybutler
Copy link
Member

coreybutler commented Dec 29, 2019

@aravindvnair99

That's a permissions issue. Windows requires administrative privileges to execute anything within or write to the C:\Program Files directory. 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).

@aravindvnair99
Copy link
Author

@aravindvnair99

That's a permissions issue. Windows requires administrative privileges to execute anything within or write to the C:\Program Files directory. 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 -g on 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.

@coreybutler
Copy link
Member

coreybutler commented Dec 30, 2019

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

@aravindvnair99
Copy link
Author

@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.1 and then installed it again via nvm 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.

coreybutler/nvm-windows#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 -g or npm i -g npm throws me the errors stated above. I have also tried it on a fresh install of Windows.

@targos targos closed this as completed Dec 28, 2020
@aravindvnair99
Copy link
Author

@targos The issue still persists.

@targos
Copy link
Member

targos commented Dec 29, 2020

Sorry, I forgot to leave a message. You should open an issue in the npm/cli repository. npm is not developed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm Issues and PRs related to the npm client dependency or the npm registry. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

5 participants