NPM Registry Proxy 配置
专栏文章
- PM2: Node.js 进程管理
- Bun: 运行JavaScript 和TypeScript 应用程序的集成工具包
- Yarn JavaScript 包管理器介绍
- nodejs 版本管理
- NPM Registry Proxy 配置(当前)
- npm 常用命令
- 使用 forever 运行 nodejs 应用
NPM Registry Proxy 配置,解决访问国外 NPM 源超时、中断等问题。
Porxy
$ npm config set proxy http://server:port
$ npm config set https-proxy http://server:port
$ cat ~/.npmrc
registry=https://mirrors.cloud.tencent.com/npm/
home=https://mirrors.cloud.tencent.com/npm/nrm
快速切换 npm 源,安装
sudo npm install -g nrm查看源:
$ nrm ls
npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.nlark.com/
npmMirror ---- https://skimdb.npmjs.com/registry/测速:
nrm test切换:
nrm use tencent其他:
nrm add <registry> <url> [home]
nrm del <registry>私有 Registry
可以使用 https://github.com/verdaccio 搭建,示例如下:
- 安装
# npm 安装
npm install --location=global verdaccio@6-next
# yarn 安装
yarn global add verdaccio@6-next
# Docker 安装
docker pull verdaccio/verdaccio:nightly-master- 启动服务
verdaccio- 使用私有仓库
npm set registry http://localhost:4873/- UI http://localhost:4873/
debug 日志
npm install --timing --loglevel verbose加速环境变量
| 环境变量名 | 推荐值 (淘宝镜像) | 作用 |
|---|---|---|
ELECTRON_MIRROR |
https://npmmirror.com/mirrors/electron/ |
告诉 @electron/get 去哪里下载 Electron 的底层可执行文件(.zip) |
PLAYWRIGHT_DOWNLOAD_HOST |
https://npmmirror.com/mirrors/playwright/ |
告诉 Playwright 去哪里下载 Chromium, Firefox 等浏览器内核 |
SENTRYCLI_CDNURL |
https://npmmirror.com/mirrors/sentry-cli/ |
告诉 @sentry/cli 去哪里下载其对应的二进制命令行工具 |
YARN_NPM_REGISTRY_SERVER |
https://registry.npmmirror.com |
(可选) Yarn 的全局 npm 镜像源,加速普通 npm 包的下载 |
一键复制使用脚本
如果是 Linux / macOS / CI 平台 (Bash):
# 1. 开启国内镜像加速
export ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
export PLAYWRIGHT_DOWNLOAD_HOST="https://npmmirror.com/mirrors/playwright/"
export SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli/"
export YARN_NPM_REGISTRY_SERVER="https://registry.npmmirror.com"
# 2. 集中设置缓存目录到项目根目录的 .cache 下
export ELECTRON_CACHE="$PWD/.cache/electron"
export PLAYWRIGHT_BROWSERS_PATH="$PWD/.cache/playwright"
export npm_config_cache="$PWD/.cache/sentry"
export YARN_CACHE_FOLDER="$PWD/.cache/yarn"
# 3. 运行安装
yarn install如果是 Windows (PowerShell):
# 1. 开启国内镜像加速
$env:ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
$env:PLAYWRIGHT_DOWNLOAD_HOST="https://npmmirror.com/mirrors/playwright/"
$env:SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli/"
$env:YARN_NPM_REGISTRY_SERVER="https://registry.npmmirror.com"
# 2. 集中设置缓存目录到项目根目录的 .cache 下
$env:ELECTRON_CACHE="$PWD\.cache\electron"
$env:PLAYWRIGHT_BROWSERS_PATH="$PWD\.cache\playwright"
$env:npm_config_cache="$PWD\.cache\sentry"
$env:YARN_CACHE_FOLDER="$PWD\.cache\yarn"
# 3. 运行安装
yarn installF&Q
self signed bug
- 错误日志
request to https://registry.npmjs.org/yarn failed, reason: self signed certificate in certificate chain- 修复方式
# npm
npm config set strict-ssl false -g
# npm set strict-ssl false
# yarn
yarn config set "strict-ssl" false
# env
set NODE_TLS_REJECT_UNAUTHORIZED=0
# 设置 ca
npm config set cafile "<path to your certificate file>"或配置环境变量:
NODE_OPTIONS = —use-openssl-ca
NODE_EXTRA_CA_CERTS = Path/To/Corporate/Certs- 上一页: Markdown Table
- 下一页: Python importlib 动态导入模块
专栏文章
- PM2: Node.js 进程管理
- Bun: 运行JavaScript 和TypeScript 应用程序的集成工具包
- Yarn JavaScript 包管理器介绍
- nodejs 版本管理
- NPM Registry Proxy 配置(当前)
- npm 常用命令
- 使用 forever 运行 nodejs 应用
最近更新
最新评论