关于npm配置国内淘宝镜像出错问题解决
今天在学习win10上安装vue环境时,在配置淘宝镜像那一步出错,出错信息如下:
C:\Users\gao>npm install -g cnpm --registry=https://registry.npm.taobao.org
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path F:\software\node_js\node_cache\_cacache
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npm.taobao.org/cnpm: EPERM: operation not permitted, mkdir 'F:\software\node_js\node_cache\_cacache'
npm ERR! at F:\software\node_js\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR! at async Arborist.[nodeFromEdge] (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR! at async Arborist.[buildDepStep] (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR! at async Arborist.buildIdealTree (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR! at async Arborist.reify (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR! at async Install.install (F:\software\node_js\node_modules\npm\lib\install.js:170:5)
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npm.taobao.org/cnpm: EPERM: operation not permitted, mkdir 'F:\software\node_js\node_cache\_cacache'
npm ERR! at F:\software\node_js\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR! at async Arborist.[nodeFromEdge] (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR! at async Arborist.[buildDepStep] (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR! at async Arborist.buildIdealTree (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR! at async Arborist.reify (F:\software\node_js\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR! at async Install.install (F:\software\node_js\node_modules\npm\lib\install.js:170:5) {
npm ERR! code: 'EPERM',
npm ERR! errno: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'F:\\software\\node_js\\node_cache\\_cacache',
npm ERR! type: 'system',
npm ERR! requiredBy: '.'
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.
我快速读了下这个报错信息,大概意思是在创建F:\\software\\node_js\\node_cache\\_cacache
(F:\software\node_js是我node.js安装源目录)这个文件错误,错误原因是权限不够,然后我查看了下我的node_cache的权限,所示如下:
- 右键node_cache文件夹,点击属性
- 点击安全,发现一共有四个用户或组,有些用户的权限不够,所以修改权限,点击编辑
- 把这四个用户或组的所有允许下面的框全部勾上
- 点击应用
- 对node_global这个文件夹也执行同样的操作,使权限全打上勾勾
- 再次执行设置淘宝镜像源命令成功:
C:\Users\gao>npm install -g cnpm --registry=https://registry.npm.taobao.org
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
added 289 packages in 25s
补充
npm config get registry # 查看npm仓库源
# 输出为 https://registry.npm.taobao.org/
cnpm config get registry # 查看cnpm仓库源
# 输出为 http://registry.npm.taobao.org/