Linux下npm全局安装Vue CLI遇EAI_AGAIN、超时等报错求助
Linux 环境下安装 Vue CLI 系列报错排查
以下为用户实际操作的终端全量记录:
# 全局安装 vue 运行时包 linux@admin:~/Masaüstü/learn-vue$ sudo npm install vue -g [sudo] password for linux: npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EAI_AGAIN: request to https://registry.npmjs.org/vue failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443 npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation. + vue@2.6.12 updated 1 package in 10.676s # 验证 vue 命令可用性 linux@admin:~/Masaüstü/learn-vue$ vue --version 'vue' komutu sistemde bulunamadı. Ama şununla kurulabilir: sudo snap install vue # 全局安装新版 Vue CLI linux@admin:~/Masaüstü/learn-vue$ npm i -g @vue/cli npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/@vue%2fcli-ui-addon-webpack (over 30000ms) npm ERR! A complete log of this run can be found in: npm ERR! /home/linux/.npm/_logs/2020-09-24T17_37_08_787Z-debug.log # 全局安装旧版 vue-cli@2.9.6 linux@admin:~/Masaüstü/learn-vue$ npm i -g vue-cli@2.9.6 npm ERR! code EAI_AGAIN npm ERR! errno EAI_AGAIN npm ERR! request to https://registry.npmjs.org/vue-cli failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443 npm ERR! A complete log of this run can be found in: npm ERR! /home/linux/.npm/_logs/2020-09-24T17_40_02_518Z-debug.log # 普通用户权限执行 npm 缓存清理 linux@admin:~/Masaüstü/learn-vue$ npm cache clean npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use `npm install --cache /tmp/empty-cache` to use a temporary cache instead of nuking the actual one. npm ERR! npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force. npm ERR! A complete log of this run can be found in: npm ERR! /home/linux/.npm/_logs/2020-09-24T17_40_33_560Z-debug.log # root 权限执行 npm 缓存清理 linux@admin:~/Masaüstü/learn-vue$ sudo npm cache clean npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use `npm install --cache /tmp/empty-cache` to use a temporary cache instead of nuking the actual one. npm ERR! npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2020-09-24T17_40_40_872Z-debug.log # root 权限强制清理 npm 缓存 linux@admin:~/Masaüstü/learn-vue$ sudo npm cache clean --force npm WARN using --force I sure hope you know what you are doing.
问题定位与解决步骤
- 网络连通性问题(所有 EAI_AGAIN、请求超时报错的根因)
当前环境无法正常解析、访问官方 npm 源registry.npmjs.org,零星安装成功的包是命中了本地缓存的旧数据,并非网络通畅。
解决操作:- 切换 npm 源为国内可正常访问的镜像地址,执行
npm config set registry https://registry.npmmirror.com - 执行
npm ping验证源连通性,返回成功响应后再进行后续操作 - 调整 npm 请求超时阈值,执行
npm config set fetch-timeout 600000,避免拉取体积较大的 CLI 包时触发默认 30s 超时
- 切换 npm 源为国内可正常访问的镜像地址,执行
- 全局安装 vue 后提示命令不存在的说明
单独全局安装的vue@2.6.12是 Vue 框架运行时核心库,不附带可执行的 CLI 命令文件,因此系统无法识别vue --version指令,这不属于安装故障。 - npm 缓存清理报错的正确处理
npm 5 之后的版本已内置缓存自愈机制,常规场景不需要手动清空缓存:- 执行
npm cache verify即可自动校验、修复损坏的缓存文件 - 仅在明确需要彻底清空缓存的调试场景,才需要搭配
--force参数执行清理
- 执行
- Vue CLI 安装验证流程
完成源配置和缓存校验后,执行sudo npm install -g @vue/cli完成新版 CLI 的全局安装,安装结束后执行vue --version能正常输出版本号,即代表安装成功。
内容的提问来源于stack exchange,提问作者Abdullah-V
相关产品推荐
相关产品推荐

