npm淘宝镜像域名变更

项目场景:

今天我从公司下载了一个新的前端项目,使用vue开发的,用npm管理包。
npm(Node Package Manager)是Node.js的包管理和分发工具,它允许你安装和管理项目
所需的依赖项。在使用npm进行包管理时,有时会遇到安装速度缓慢的问题。这可能是由于
网络原因或npm官方镜像服务器的繁忙导致的。解决安装速度慢,可以使用淘宝镜像:
npm config set registry https://registry.npm.taobao.org,
然后再使用 npm install

问题描述

在使用淘宝镜像安装的过程中爆了下面的错
  Could not fetch metadata for @ampproject/remapping@2.1.2 FetchError: 
  request to https://registry.npm.taobao.org/@ampproject%2fremapping 
  failed, reason: certificate has expired     

在这里插入图片描述

原因分析:

看提示是淘宝镜像过期了。找了一下资料,好像是npm 淘宝镜像已经从 registry.npm.taobao.org 切换到了 registry.npmmirror.com。旧域名也将于 2022 年 5 月 31 日停止服务(不过,直到最近 HTTPS 证书到期才真正不能用了)


解决方案:

国内用户还是建议使用淘宝镜像,所以推荐还是设置成用淘宝镜像:

1.npm config set registry https://registry.npmmirror.com

2.npm config list,查看 registry 已经被更改为默认的 npm 公共镜像地址

3.然后再使用 npm install

### 淘宝镜像源最新地址及配置方法 #### 1. 最新淘宝镜像源地址 淘宝镜像源的最新地址已更改为 `https://registry.npmmirror.com`[^1]。原域名 `https://registry.npm.taobao.org/` 已于 2022 年 6 月 30 日正式下线并停止 DNS 解析。 --- #### 2. 使用 npm 配置淘宝镜像源的方法 可以通过以下命令将 npm 的默认注册表设置为最新的淘宝镜像源: ```bash npm config set registry https://registry.npmmirror.com ``` 验证当前使用的注册表地址是否成功切换至新的镜像源,可以运行以下命令: ```bash npm get registry ``` 如果返回的结果是 `https://registry.npmmirror.com`,则表示配置成功[^3]。 --- #### 3. 使用 Yarn 配置淘宝镜像源的方法 对于使用 Yarn 的开发者,同样需要将其注册表地址更新为最新的淘宝镜像源: ```bash yarn config set registry https://registry.npmmirror.com ``` 之后可通过以下命令确认配置是否生效: ```bash yarn config get registry ``` 若结果显示为 `https://registry.npmmirror.com`,说明配置已完成[^3]。 --- #### 4. 常见依赖项的镜像配置 除了全局注册表外,某些特定依赖项可能还需要额外配置其对应的镜像站点。以下是部分常用依赖项及其推荐的镜像地址[^2]: | **依赖名称** | **镜像地址** | |----------------------|--------------------------------------------------| | sharp | `sharp_binary_host = https://npmmirror.com/mirrors/sharp` | | sharp-libvips | `sharp_libvips_binary_host = https://npmmirror.com/mirrors/sharp-libvips` | | node-inspector | `profiler_binary_host_mirror = https://npmmirror.com/mirrors/node-inspector/` | | fsevents | `fse_binary_host_mirror = https://npmmirror.com/mirrors/fsevents` | | sqlite3 | `node_sqlite3_binary_host_mirror = https://npmmirror.com/mirrors/sqlite3` | | node-sass | `sass_binary_site = https://npmmirror.com/mirrors/node-sass` | | electron | `electron_mirror = https://npmmirror.com/mirrors/electron/` | | puppeteer | `puppeteer_download_host = https://npmmirror.com/mirrors` | | chromedriver | `chromedriver_cdnurl = https://npmmirror.com/mirrors/chromedriver` | | operadriver | `operadriver_cdnurl = https://npmmirror.com/mirrors/operadriver` | | phantomjs | `phantomjs_cdnurl = https://npmmirror.com/mirrors/phantomjs` | 这些配置可以在项目的 `.npmrc` 文件中手动添加,或者通过环境变量动态注入。 --- #### 5. 自动化构建工具中的配置建议 为了提升项目在 CI/CD 流程中的稳定性,建议在自动化构建脚本中加入上述镜像地址的配置。例如,在 Dockerfile 或 shell 脚本中执行如下操作: ```dockerfile RUN npm config set registry https://registry.npmmirror.com && \ echo 'sharp_binary_host=https://npmmirror.com/mirrors/sharp' >> ~/.npmrc && \ echo 'electron_mirror=https://npmmirror.com/mirrors/electron/' >> ~/.npmrc ``` 这一步骤能够有效减少因网络问题导致的安装失败风险。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值