actions / setup-node

Set up your GitHub Actions workflow with a specific version of node.js
MIT License
3.94k stars 1.3k forks source link

Windows: Cannot update global npm version after using setup-node #623

Closed peterjuras closed 1 year ago

peterjuras commented 2 years ago

Description: This bug already happened in the past (#411), but appears to be happening again. Up until now, updating the global npm version after setting up the node version using npm install -g npm worked on all operating systems without issues.

Now I'm receiving the following errors:

Log output npm WARN rollback Rolling back @npmcli/fs@2.1.2 failed (this is probably harmless): EPERM: operation not permitted, lstat 'C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli' npm ERR! code EPERM npm ERR! syscall rename npm ERR! path C:\npm\prefix\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli npm ERR! dest C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli npm ERR! errno -4048 npm ERR! Error: EPERM: operation not permitted, rename 'C:\npm\prefix\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli' npm ERR! [OperationalError: EPERM: operation not permitted, rename 'C:\npm\prefix\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli'] { npm ERR! cause: [Error: EPERM: operation not permitted, rename 'C:\npm\prefix\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli'] { npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'rename', npm ERR! path: 'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\.node-gyp.DELETE\\node_modules\\@npmcli', npm ERR! dest: 'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp\\node_modules\\@npmcli' npm ERR! }, npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'rename', npm ERR! path: 'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\.node-gyp.DELETE\\node_modules\\@npmcli', npm ERR! dest: 'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp\\node_modules\\@npmcli', npm ERR! parent: '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. npm ERR! A complete log of this run can be found in: npm ERR! C:\npm\cache\_logs\2022-11-14T05_03_05_6[7](https://github.com/coat-dev/coat/actions/runs/3457231320/jobs/5773299135#step:4:8)2Z-debug.log Error: Process completed with exit code 1.

Action version: Pinned at v3

Platform:

Runner type:

Tools version: Node.js 14, potentially also failing for other node versions.

Repro steps:
See failed job in public repo.

Expected behavior: npm should install and update the global version correctly.

Actual behavior: Updating the npm version fails.

dsame commented 2 years ago

Hello @peterjuras, thanks for your input. We are starting to investigate the problem.

peterjuras commented 2 years ago

Thanks! It might be related to the file permission changes with npm@9

dmitry-shibanov commented 2 years ago

Hello @peterjuras. Could you please try to use this npm i -g npm@8 && npm i -g npm@latest command.

dsame commented 2 years ago

@peterjuras it looks like the problem is there's no pre-built @npmcli package of 9th version for node14 and node-gyp fails to build it from source code.

While i am looking for the proof of this hypothesis please try to skip the combination of node14/npm9 as a workaround if possible.

dsame commented 2 years ago

@peterjuras yes, the problem exists with the native node binary and does not depend on the action.

https://github.com/akv-demo/setup-node-test/actions/runs/3463429592/jobs/5783651246#step:2:24

The npm team should be addressed with the issue of installing npm9 with node 14 to solve.

peterjuras commented 2 years ago

I created a new issue in the npm cli repo: https://github.com/npm/cli/issues/5856

wraithgar commented 2 years ago

Hello @peterjuras. Could you please try to use this npm i -g npm@8 && npm i -g npm@latest command.

This is the right suggestion. npm 6 has an issue installing some newer versions of npm in windows because of a bug in how it tries to shuffle directories around. We had to work around this ourselves when developing npm 7: node images that shipped with npm 6 had to be leapfrogged from a lower version of 7 that npm 6 could install, and from there we could install the latest npm.

We used to have a pinned issue about this in npm 7, looks like we'll need another one to help folks updating from npm 6. https://github.com/npm/cli/issues/5862 will be updated as we go along.

dsame commented 1 year ago

Hello @peterjuras , i am closing the issue because it does not relate to setup-node repo, but please feel free to reopen it or create another one in case if feel the problem still should solved by us.

peterjuras commented 1 year ago

Hello @peterjuras. Could you please try to use this npm i -g npm@8 && npm i -g npm@latest command.

This is the right suggestion. npm 6 has an issue installing some newer versions of npm in windows because of a bug in how it tries to shuffle directories around. We had to work around this ourselves when developing npm 7: node images that shipped with npm 6 had to be leapfrogged from a lower version of 7 that npm 6 could install, and from there we could install the latest npm.

We used to have a pinned issue about this in npm 7, looks like we'll need another one to help folks updating from npm 6. npm/cli#5862 will be updated as we go along.

Thanks, this worked for me 👍