这个错误是在使用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_global
和node_cache
两个文件的普通用户权限打开,操作步骤为: