You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法访问常用npm registry,求可用源及npm包安装解决方案

可行的npm包安装方案及可用源列表

可用的npm Registry列表

以下是目前可正常访问的npm镜像源:

  • https://registry.npmmirror.com/(原淘宝npm源的官方替代镜像)
  • https://mirrors.cloud.tencent.com/npm/(腾讯云npm镜像)
  • https://mirrors.aliyun.com/npm/(阿里云npm镜像)
  • https://repo.huaweicloud.com/repository/npm/(华为云npm镜像)
  • https://npm.pkg.github.com/(用于安装GitHub私有包)

切换npm源的方法

临时指定源安装(单次生效)

安装单个包时直接通过--registry参数指定源:

npm install <你的包名> --registry=https://registry.npmmirror.com/

永久设置默认源

  1. 配置默认镜像源:
npm config set registry https://registry.npmmirror.com/
  1. 验证配置是否成功:
npm config get registry
  1. 如需切换其他源,重复上述命令替换对应URL即可。

使用nrm管理源(可选)

nrm是一款npm源管理工具,可快速切换不同镜像源:

  1. 先全局安装nrm(需临时使用可用源安装):
npm install -g nrm --registry=https://registry.npmmirror.com/
  1. 查看所有可用源:
nrm ls
  1. 切换到目标源:
nrm use npmmirror

其他安装方法

本地文件安装

若能获取到包的.tar.gz压缩包,可直接本地安装:

npm install /本地路径/包名.tar.gz

GitHub仓库直接安装

如果包托管在GitHub,可通过仓库地址直接安装:

npm install github:<用户名>/<仓库名>
# 指定分支或标签安装
npm install github:<用户名>/<仓库名>#<分支名/标签>

使用yarn替代npm

yarn的源配置逻辑与npm一致,可切换源后使用yarn安装:

yarn config set registry https://registry.npmmirror.com/
yarn add <你的包名>

内容的提问来源于stack exchange,提问作者Kerim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 19:35:26