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

[BUG] EPERM error 4048 installing latest npm when on version 7.5.3 #2663

Closed
acohenOT opened this issue Feb 9, 2021 · 18 comments
Closed

[BUG] EPERM error 4048 installing latest npm when on version 7.5.3 #2663

acohenOT opened this issue Feb 9, 2021 · 18 comments
Assignees
Labels
Bug thing that needs fixing platform:windows is Windows-specific Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release

Comments

@acohenOT
Copy link

acohenOT commented Feb 9, 2021

Current Behavior:

Installing latest npm version when on 7.5.3 generates an error:

npm -v
7.5.3
npm i -g npm
npm ERR! code EPERM
npm ERR! syscall rename
npm ERR! path C:\Program Files\nodejs\node_modules\npm
npm ERR! dest C:\Program Files\nodejs\node_modules\.npm-QXjMEw5N
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Program Files\nodejs\node_modules\npm' -> 'C:\Program Files\nodejs\node_modules\.npm-QXjMEw5N'
npm ERR!  [Error: EPERM: operation not permitted, rename 'C:\Program Files\nodejs\node_modules\npm' -> 'C:\Program Files\nodejs\node_modules\.npm-QXjMEw5N'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'rename',
npm ERR!   path: 'C:\\Program Files\\nodejs\\node_modules\\npm',
npm ERR!   dest: 'C:\\Program Files\\nodejs\\node_modules\\.npm-QXjMEw5N'
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.

Expected Behavior:

npm should be installed globally without error. If 7.5.3 is (still) the latest version, no change occurs

Steps To Reproduce:

  1. Windows 10 x64 environment with node 14.5.4 and npm 7.5.3 installed
  2. Run npm i -g npm
  3. See error with regard to renaming a file

Environment:

OS: Windows 10 x64
Node: 14.5.4
npm: 7.5.3

@acohenOT acohenOT added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Feb 9, 2021
@websam101
Copy link

websam101 commented Feb 10, 2021

+1 with a variant that makes --global unusable after update. (Solved on >= 7.5.4)

Current Behavior:

Updating global with latest npm version 7.5.3 generates an error even on elevated privileges:

npm ERR! code EPERM
npm ERR! syscall rename
npm ERR! path C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\encoding\lib
npm ERR! dest C:\Users\User\AppData\Roaming\npm\node_modules\.npm-aTNIHvdH\node_modules\encoding\lib
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\encoding\lib' -> 'C:\Users\User\AppData\Roaming\npm\node_modules\.npm-aTNIHvdH\node_modules\encoding\lib'
npm ERR!  [Error: EPERM: operation not permitted, rename 'C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\encoding\lib' -> 'C:\Users\User\AppData\Roaming\npm\node_modules\.npm-aTNIHvdH\node_modules\encoding\lib'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'rename',
npm ERR!   path: 'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\encoding\\lib',
npm ERR!   dest: 'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\.npm-aTNIHvdH\\node_modules\\encoding\\lib'
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.

Expected Behavior:

npm should be updated globally without error.

Steps To Reproduce:

  1. Windows 10 x64 environment with node 14.15.5 and npm 7.5.3 installed
  2. Run npm -g update
  3. See error with regard to renaming files and folders

Environment:

OS: Windows 10 x64
Node: 14.15.5 + 15.8.0
npm: 7.5.2 + 7.5.3

@robross0606
Copy link

robross0606 commented Feb 11, 2021

I am seeing this exact same problem. This should be a SEVERITY ONE. It can bork the entire node.js installation when npm goes belly up like this. I can confirm that I have checked permissions on the folder, tried running as Administrator, and ensure my AV product was disabled.

@darcyclarke darcyclarke added platform:windows is Windows-specific and removed Needs Triage needs review for next steps labels Feb 12, 2021
@darcyclarke
Copy link
Contributor

@acohenOT can you try installing the latest npm & seeing if you can repro? (ie. npm i npm@latest -g - 7.5.4)

@darcyclarke darcyclarke added the Priority 1 high priority issue label Feb 12, 2021
@websam101
Copy link

websam101 commented Feb 12, 2021

7.5.4 solved it for the global update variant but in elevated mode when i have entered:

npm update -g windows-build-tools

npm has deleted all the other packages in the global folders:

C:\Users\User\AppData\Roaming\npm
C:\Users\User\AppData\Roaming\npm\node_modules

leaving only windows-build-tools.
npm has reverted itself to v7.5.1
and both 7.5.1 and 7.5.4 have the same behavior with this update global package command on elevated prompt.

❯ npm update -g windows-build-tools
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142

removed 4589 packages, changed 147 packages, and audited 148 packages in 10m

6 packages are looking for funding
  run `npm fund` for details

3 low severity vulnerabilities

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

@acohenOT
Copy link
Author

I'm unable to install 7.5.4 because I get the error.

npm i -g [email protected]

npm ERR! code EPERM
npm ERR! syscall rename
npm ERR! path C:\Users\cohena\AppData\Roaming\npm\node_modules\npm
npm ERR! dest C:\Users\cohena\AppData\Roaming\npm\node_modules\.npm-Snvm3Zqx
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Users\cohena\AppData\Roaming\npm\node_modules\npm' -> 'C:\Users\cohena\AppData\Roaming\npm\node_modules\.npm-Snvm3Zqx'
npm ERR!  [Error: EPERM: operation not permitted, rename 'C:\Users\cohena\AppData\Roaming\npm\node_modules\npm' -> 'C:\Users\cohena\AppData\Roaming\npm\node_modules\.npm-Snvm3Zqx'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'rename',
npm ERR!   path: 'C:\\Users\\cohena\\AppData\\Roaming\\npm\\node_modules\\npm',
npm ERR!   dest: 'C:\\Users\\cohena\\AppData\\Roaming\\npm\\node_modules\\.npm-Snvm3Zqx'
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\cohena\AppData\Local\npm-cache\_logs\2021-02-12T21_23_15_321Z-debug.log

npm -v is still showing 7.5.3

Does anyone know how to force the update to 7.5.4?

@ljharb
Copy link
Contributor

ljharb commented Feb 12, 2021

@acohenOT in your case you may have to sudo npm install -g npm@7

@acohenOT
Copy link
Author

I'm running in a Windows command prompt so sudo will not work there. I'm already running cmd.exe with elevated privileges.

@websam101
Copy link

@acohenOT for npm 7.5.4 on windows: npm -g install npm@latest

@Wyzix33
Copy link

Wyzix33 commented Feb 12, 2021

running npm -g install npm@latest on windows 10 on cmd as administrator is not working
this was after a clean install of nodejs and a restart ...

C:\WINDOWS\system32>npm -v
7.5.3

C:\WINDOWS\system32>npm -g install npm@latest
npm ERR! code EPERM
npm ERR! syscall rename
npm ERR! path C:\Program Files\nodejs\node_modules\npm
npm ERR! dest C:\Program Files\nodejs\node_modules\.npm-QXjMEw5N
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, rename 'C:\Program Files\nodejs\node_modules\npm' -> 'C:\Program Files\nodejs\node_modules\.npm-QXjMEw5N'
npm ERR!  [Error: EPERM: operation not permitted, rename 'C:\Program Files\nodejs\node_modules\npm' -> 'C:\Program Files\nodejs\node_modules\.npm-QXjMEw5N'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'rename',
npm ERR!   path: 'C:\\Program Files\\nodejs\\node_modules\\npm',
npm ERR!   dest: 'C:\\Program Files\\nodejs\\node_modules\\.npm-QXjMEw5N'
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\G\AppData\Local\npm-cache\_logs\2021-02-12T23_44_48_082Z-debug.log

@darcyclarke
Copy link
Contributor

@acohenOT thank you again for filing this. I've marked it as a high priority issue & will be looking at this again post the v7.5.4 release published yesterday; If you can* (ie. anyone reading) try updating (ie. npm i -g npm@latest - latest today is v7.5.4) & posting back whether or not this is still an issue for you, that would be much appreciated.

Apologize if you're still experiencing issues trying to install. We recommend using a Node Version Manager if you can (ex. Volta, nvm or nvs as listed in our README.md) but if those aren't helping then there's definitely something else afoot.

Appreciate all the added context, we'll report back again early next week, ideally with a patch for this if we can get a reproduction case going.

@cristiammercado
Copy link

cristiammercado commented Feb 14, 2021

Hi people,

I had the same problem yesterday. I updated NodeJS in my Win10 machine to 14.15.5 and I had installed npm 7.5.3 from a previous global installation. When I tried to update npm to version 7.5.4 I couldn't do it, I got the error of administrator permissions described above and I had never happened. The same thing also happened to me if I wanted to install any package globally (for example: npm install -g @angular/cli).

What I did to fix it was to completely uninstall nodejs, check there were no files left in C:\Program Files\node and then I deleted all global packages from C:\Users\<username>\AppData\Roaming\npm (including cache folder: npm-cache) and I did a clean install of NodeJS 14.15.5 again, which includes npm 6.14.11. Once this was done I executed npm install -g npm@latest again and I could install version 7.5.4 without any problems and I was able to reinstall global packages again.

In conclusion, I think the problem is in version 7.5.3, which was the one I had installed on my machine at the time of the error, because I'm using 7.5.4 now without problems, I can install global packages again and even execute npm install -g npm@latest without errors.

Thanks!

@acohenOT
Copy link
Author

Thank you @cristiammercado -- those steps worked for me as well! Definitely a problem with 7.5.3.

@Wyzix33
Copy link

Wyzix33 commented Feb 15, 2021

Thank you @cristiammercado, this worked with node-v15.8.0-x64.msi as well wich came with npm version 7.5.1.

@nlf
Copy link
Contributor

nlf commented Feb 16, 2021

the bug is, indeed, a problem in [email protected]. once you're on 7.5.4 you should be fine!

if you're on 7.5.3 and stuck, and also have bash, you can try our bash script installer by running curl -q https://www.npmjs.com/install.sh | sh

if you do not have bash, see the super helpful post above by @cristiammercado

I'm going to close this issue since we do have multiple reports of the problem being fixed in 7.5.4, if anyone sees this problem happen when you already have 7.5.4 or newer installed, please open a new issue and let us know

@nlf nlf closed this as completed Feb 16, 2021
@robross0606
Copy link

robross0606 commented Feb 16, 2021

@nlf, I appreciate that this bug was fixed in 7.5.4, but the bug report was about being stuck on 7.5.3 and a full solution hasn't actually been addressed. How do you solve this problem if you are stuck on 7.5.3 and don't have bash?

@acohenOT
Copy link
Author

@robross0606, see the solution provided by @cristiammercado #2663 (comment)

@robross0606
Copy link

@robross0606, see the solution provided by @cristiammercado #2663 (comment)

Okay, so basically nuke the entire installation and start over.

@ishaiknadeem
Copy link

I was facing the same problem for 3 days and got this solution for it...

It's because of old files lying in your c drive:

Follow the steps below and try, It will work for sure.

problem:

npm ERR! Errno: -4048, npm ERR! code: ‘EPERM’, npm ERR! syscall: ‘scandir’,

solution:

Uninstall node with node uninstaller ( find it from run cmd )

Then...

Delete the npmrc file and delete the C:\Users\Administrator.npmrc file ( if don't find leave it )

Delete npm-cache folder from - C:\Users\Administrator\AppData\Roaming

Delete npm folder from - C:\Users\Administrator\AppData\Roaming

Restart your system and install fresh NodeJS and run this command in cmd: npm cache clean -–force to ensure the cache is cleared.

That's your ready to go now...

If you still face a problem feel free to get in touch with me @ishaiknadeem username on any platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing platform:windows is Windows-specific Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

9 participants