cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] <title>On WIndows, npm 24 prefix defaults to "C:\Program Files\nodejs" which it doesn't have write permission

Open tribbloid opened this issue 1 month ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

This issue exists in the latest npm version

  • [x] I am using the latest npm

Current Behavior

$ npm config get prefix
C:\Program Files\nodejs

$ npm config list
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v24.11.1
; npm local prefix = C:\Users\pengc
; npm version = 11.6.2
; cwd = C:\Users\pengc
; HOME = C:\Users\pengc
; Run `npm config ls -l` to show all defaults.

this caused npm update -g to throw the following error:

npm update -g
npm error code EPERM
npm error syscall mkdir
npm error path C:\Program Files\nodejs\node_modules\.corepack-yRBjKBW1
npm error errno -4048
npm error Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.corepack-yRBjKBW1'
npm error     at async Object.mkdir (node:internal/fs/promises:861:10)
npm error     at async moveFile (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\fs\lib\move-file.js:27:3)
npm error     at async Promise.all (index 0)
npm error     at async moveFile (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\fs\lib\move-file.js:36:9)
npm error     at async Promise.allSettled (index 0)
npm error     at async [reifyPackages] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:313:11)
npm error     at async Arborist.reify (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:125:5)
npm error     at async Update.exec (C:\Program Files\nodejs\node_modules\npm\lib\commands\update.js:64:5)
npm error     at async Npm.exec (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:208:9)
npm error     at async module.exports (C:\Program Files\nodejs\node_modules\npm\lib\cli\entry.js:67:5) {
npm error   errno: -4048,
npm error   code: 'EPERM',
npm error   syscall: 'mkdir',
npm error   path: 'C:\\Program Files\\nodejs\\node_modules\\.corepack-yRBjKBW1'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It's possible that the file was already in use (by a text editor or antivirus),
npm error or that you lack permissions to access it.
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
npm error A complete log of this run can be found in: C:\Users\pengc\AppData\Local\npm-cache\_logs\2025-11-19T18_28_42_563Z-debug-0.log

Expected Behavior

default prefix should be "${USER_DIR}\AppData\Roaming\npm" on windows

Steps To Reproduce

install Node.js on windows

Environment

  • npm:
  • Node.js:
  • OS Name:
  • System Model Name:
  • npm config:
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v24.11.1
; npm local prefix = C:\Users\pengc
; npm version = 11.6.2
; cwd = C:\Users\pengc
; HOME = C:\Users\pengc
; Run `npm config ls -l` to show all defaults.

tribbloid avatar Nov 19 '25 18:11 tribbloid

npm config list.....you are missing

; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc

prefix = "C:\\Users\\InsertUserName\\AppData\\Roaming\\npm"

How did you install NodeJS?


If you add a file called npmrc to C:\Users\InsertUserName\AppData\Roaming\npm with contents:

prefix=${APPDATA}\npm

it should fix the issue for you

alexsch01 avatar Nov 19 '25 20:11 alexsch01

I installed it though WinGet/UniGet, yes adding user-specific is easy and already been done, but it should be the default.

tribbloid avatar Nov 20 '25 02:11 tribbloid