npm升级报错,没有权限.ERRERR!The operation was rejected by your operating system. npm ERR!Error: EPERM: operation not permitted, rename

问题描述

Windows system32>npm installg npm

2335 error code EEXIST
2336 error path D:\Program Files\nodejs\npm.cmd
2337 error Refusing to delete D:\Program Files\nodejs\npm.cmd: is outside D:\Program Files\nodejs\node_modules\npm and not a link
2338 error File exists: D:\Program Files\nodejs\npm.cmd
2339 error Remove the existing file and try again, or run npm
2340 error with --force to overwrite files recklessly.

A complete log of this run can be found in: ERRc:\Users\abc\AppData Roaming npm-cache logs\2022-12-13T06 02 45 049Z-debug.log

 

 

C: Windows system32>npm install npm -g --force

3451 error code EPERM
3452 error syscall rename
3453 error path C:\Windows\system32\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli
3454 error dest C:\Windows\system32\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli
3455 error errno -4048
3456 error Error: EPERM: operation not permitted, rename 'C:\Windows\system32\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'C:\Windows\system32\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli'
3456 error  [OperationalError: EPERM: operation not permitted, rename 'C:\Windows\system32\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'C:\Windows\system32\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli'] {
3456 error   cause: [Error: EPERM: operation not permitted, rename 'C:\Windows\system32\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'C:\Windows\system32\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli'] {
3456 error     errno: -4048,
3456 error     code: 'EPERM',
3456 error     syscall: 'rename',
3456 error     path: 'C:\\Windows\\system32\\node_modules\\npm\\node_modules\\.node-gyp.DELETE\\node_modules\\@npmcli',
3456 error     dest: 'C:\\Windows\\system32\\node_modules\\npm\\node_modules\\node-gyp\\node_modules\\@npmcli'
3456 error   },
3456 error   errno: -4048,
3456 error   code: 'EPERM',
3456 error   syscall: 'rename',
3456 error   path: 'C:\\Windows\\system32\\node_modules\\npm\\node_modules\\.node-gyp.DELETE\\node_modules\\@npmcli',
3456 error   dest: 'C:\\Windows\\system32\\node_modules\\npm\\node_modules\\node-gyp\\node_modules\\@npmcli',
3456 error   parent: 'npm'
3456 error }
3457 error The operation was rejected by your operating system.
3457 error It's possible that the file was already in use (by a text editor or antivirus),
3457 error or that you lack permissions to access it.
3457 error
3457 error If you believe this might be a permissions issue, please double-check the
3457 error permissions of the file and its containing directories, or try running
3457 error the command again as root/Administrator.

 

解决方案:

npm config set prefix "D:\nodejs\node_global"

npm config set cache "D:\nodejs\node_cache"

参考文档:https://blog.csdn.net/qq_31989047/article/details/108755783

分析原因:估计是原来装过nodejs,然后系统权限发生过变更,原有文件夹失去了权限.

 

这个问题折磨了我,2天,哭死.

 

posted @ 2022-12-13 15:12  Easy999000  阅读(3537)  评论(0编辑  收藏  举报