每当我使用 npm 安装任何东西时,我都会收到以下错误列表:
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Users\Firstname~1
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Users\Firstname~1'
npm ERR! [OperationalError: EPERM: operation not permitted, mkdir 'C:\Users\Firstname~1'] {
npm ERR! cause: [Error: EPERM: operation not permitted, mkdir 'C:\Users\Firstname~1'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'C:\\Users\\Firstname~1'
npm ERR! },
npm ERR! isOperational: true,
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'C:\\Users\\Firstname~1'
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 install?
答案 0 :(得分:1)
看起来像是 npm 配置错误问题。
理想情况下,您可以将其配置为仅使用您的用户有权访问的目录,因此您不需要管理员权限即可安装全局包。
首先,使用类似的命令检查 npm 前缀是什么
npm config ls -l
我打赌它会显示类似
prefix = "C:\\Users\\"
尝试在 C:\Users{username}\ 创建,其中 {username} 是你自己的,一个带有类似条目的 .npmrc 文件
prefix = "C:\\Users\\{username}\\some_dir_you_have_access"
然后像 npm install -g package 一样使用 -g,这样 npm 会尝试在你定义的“prefix”指定的路径中安装全局包。
npm 文件夹记录在此处 https://docs.npmjs.com/cli/v7/configuring-npm/folders