Skip to content
00:00:00
0

文章发布较早,内容可能过时,阅读注意甄别。

npm报错 operation not permitted, open

这个错误是在使用 npm 下载依赖时发生的,错误如下 npm ERR! code EPERM npm ERR! syscall open npm ERR! path E:\nodejs\npm_cache_cacache\tmp\7ab9b301 npm ERR! errno -4048 npm ERR! Error: EPERM: operation not permitted, open 'E:\nodejs\npm_cache_cacache\tmp\7ab9b301' npm ERR! [Error: EPERM: operation not permitted, open 'E:\nodejs\npm_cache_cacache\tmp\7ab9b301'] { npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'open', npm ERR! path: 'E:\nodejs\npm_cache\_cacache\tmp\7ab9b301' 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:

原因是新换了电脑,nodejs 也是新安装的,因为 npm 安装全局依赖和缓存的默认路径在 c 盘,而我为了不占用 c 盘的空间,使用命令修改文件保存目录,命令行如下:

npm config set prefix "E:\nodejs\npm_global"
npm config set cache "E:\nodejs\node_cache"

这就导致了一个问题,新的文件夹,普通用户没有完全控制的权限,导致 npm 操作受阻,解决方案有两个:

  • 1.使用管理员权限操作 cmd(这个方法要么每次打开时注意,要么直接设置 cmd 默认管理员打开)
  • 2.将npm_globalnode_cache两个文件的普通用户权限打开,操作步骤为:

第一步全部勾选即可

ok 解决!

最近更新