看到一篇文章,说是 npm.taobao.orgregistry.npm.taobao.org 域名将于 2022 年 05 月 31 日起停止服务。有必要更新一下 npm 的源,顺便复习一下 npm 的一些列命令

查看 npm 配置

1
2
npm config list // 查看基本配置
npm config list -l // 查看所有配置

image-20220211095840101

没找到,拿查看所有配置看看,一查发现 metrics-registry = "https://registry.npmjs.org/",那就说明源还是 npmjs 的源,看来公司电脑的 npm 用的还是 npm 官方的源,而全局还下载了 cnpm,因为是 npm 包,所以看版本,远程拉去最新的即可,先看看版本

1
cnpm -v

image-20220211101038446

查看 cnpm 的官网:中国 NPM 镜像 ,文中有这么一句:

当前 registry.npmmirror.com 是从 r.cnpmjs.org 进行全量同步的.

发现也没什么关系,所以我应该不会被影响

如何更新安装包

  1. 手动更新
    • 修改 package.json 中依赖包版本,执行 npm install --force
  2. 使用 yarn 代替 npm
    • yarn upgrade
  3. 使用第三方插件
    • npm install npm-check-updates -g
    • ncu // 查看可更新包
    • ncu -u // 更新 package.json
    • npm install // 升级最新版本

发现第三种最有用

参考资料