解决npm i 报错显示 code EPERM syscall rename等问题

发布时间 2023-06-10 09:45:55作者: 樹恱人生

问题描述:
npm ERR! code EPERM
npm ERR! syscall rename
npm ERR! path D:\Program Files\nodejs\npm_global\node_modules\cnpm\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli
npm ERR! dest D:\Program Files\nodejs\npm_global\node_modules\cnpm\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, rename 'D:\Program Files\nodejs\npm_global\node_modules\cnpm\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'D:\Program Files\nodejs\npm_global\node_modules\cnpm\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli'
npm ERR! [OperationalError: EPERM: operation not permitted, rename 'D:\Program Files\nodejs\npm_global\node_modules\cnpm\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'D:\Program Files\nodejs\npm_global\node_modules\cnpm\node_modules\npm\node_modules\node-gyp\node_modules\@npmcli'] {
npm ERR! cause: [Error: EPERM: operation not permitted, rename 'D:\Program Files\nodejs\npm_global\node_modules\cnpm\node_modules\npm\node_modules\.node-gyp.DELETE\node_modules\@npmcli' -> 'D:\Program Files\nodejs\npm_global\node_modules\cnpm\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: 'D:\\Program Files\\nodejs\\npm_global\\node_modules\\cnpm\\node_modules\\npm\\node_modules\\.node-gyp.DELETE\\node_modules\\@npmcli',
npm ERR! dest: 'D:\\Program Files\\nodejs\\npm_global\\node_modules\\cnpm\\node_modules\\npm\\node_modules\\node-gyp\\node_modules\\@npmcli'
npm ERR! },
npm ERR! stack: "Error: EPERM: operation not permitted, rename 'D:\\Program Files\\nodejs\\npm_global\\node_modules\\cnpm\\node_modules\\npm\\node_modules\\.node-gyp.DELETE\\node_modules\\@npmcli' -> 'D:\\Program Files\\nodejs\\npm_global\\node_modules\\cnpm\\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: 'D:\\Program Files\\nodejs\\npm_global\\node_modules\\cnpm\\node_modules\\npm\\node_modules\\.node-gyp.DELETE\\node_modules\\@npmcli',
npm ERR! dest: 'D:\\Program Files\\nodejs\\npm_global\\node_modules\\cnpm\\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! D:\Program Files\nodejs\npm_cache\_logs\2023-06-10T01_18_26_519Z-debug.log

 

解决方法:

1、需要删除.npmrc文件(找到用户目录下C:\Users\用户名\.npmrc)。

注意:本人node安装目录为D:\Program Files\nodejs,而D:\Program Files\nodejs\node_modules\npm下也存在.npmrc的文件,删除的不是本目录下的文件,而是删除C盘用户下的.npmrc文件

2、以管理员身份运行CMD,在窗口执行 npm install nrm -g 即可。