question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

npm ERR! code EPERM
npm ERR! syscall rename
npm ERR! path C:\npm\prefix\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@tootallnate
npm ERR! dest C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@tootallnate
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\@tootallnate' -> 'C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@tootallnate'
npm ERR!  [OperationalError: EPERM: operation not permitted, rename 'C:\npm\prefix\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@tootallnate' -> 'C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@tootallnate'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, rename 'C:\npm\prefix\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@tootallnate' -> 'C:\npm\prefix\node_modules\npm\node_modules\node-gyp\node_modules\@tootallnate'] {
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\\@tootallnate',
npm ERR!     dest: 'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp\\node_modules\\@tootallnate'
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\\@tootallnate',
npm ERR!   dest: 'C:\\npm\\prefix\\node_modules\\npm\\node_modules\\node-gyp\\node_modules\\@tootallnate',
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-01-29T07_32_14_023Z-debug.log

Action version: 2.5.1 (pinned at @2)

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version: Trying to set up node 12, likely also an issue with other node versions.

Repro steps:

You can see an example action run here. The failed workflow runs npm install -g npm after using the setup-node action, the passing run runs it without using the setup-node action.

Workflow configuration used in the example above:

name: github-actions-windows-npm-install-test
on:
  push:
jobs:
  win-setup-node-action:
    name: "WIN: Global npm install with setup-node action"
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 12
      - name: Install latest npm version
        run: npm install --global npm
  win-preinstalled-node:
    name: "WIN: Global npm install without setup-node action"
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install latest npm version
        run: npm install --global npm

Expected behavior:

npm install -g npm should globally install the newest npm version and overwrite the default version that comes with node 12, 14 etc.

Actual behavior:

npm install -g npm fails due to permissions errors on Windows and breaks the workflow run.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:13
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
dmitry-shibanovcommented, Jan 31, 2022

Hello everyone. Thank you for your report. I think it should be related to this issue. As a workaround for now you can specify npm version as 8.3.1.

      - name: Install latest npm version
        run: npm install --global npm@8.3.1
7reactions
michael-strother-wthcommented, Feb 7, 2022

I ran into the same issue… installing 8.3.1 as a workaround worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot update global npm version after using setup-node ...
Description: This bug already happened in the past (#411), but appears to be happening again. Up until now, updating the global npm version...
Read more >
How can I update npm on Windows? - node.js - Stack Overflow
You can update your npm to the latest stable version with the following command: npm install npm@latest -g. Use PowerShell to run it....
Read more >
Try the latest stable version of npm
Go into %ProgramFiles%\nodejs\node_modules\npm and copy the file named npmrc in the new npm folder, which should be %appdata%\npm\node_modules\npm . This will ...
Read more >
Installing - Express.js
Use the npm init command to create a package.json file for your application. ... for a number of things, such as the name...
Read more >
Node JS Environment Setup - Node.js installation - DigitalOcean
Check Node JS Version: Use the following command to know your Node JS Version from Command prompt. node –v Node.js-cmd-windows-version ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found