使用 verdaccio 搭建本地仓库

449 阅读2分钟

使用 verdaccio 搭建本地仓库

使用教程

安装

npm install -g verdaccio

启动

verdaccio

常见问题

502 Bad Gateway

在执行 npm adduser --registry http://localhost:4873/npm publish 时,出现如下报错:

C:\Users\Admin>npm adduser
npm notice Log in on http://localhost:4873/
npm ERR! code E502
npm ERR! 502 Bad Gateway - POST http://localhost:4873/-/v1/login

npm ERR! A complete log of this run can be found in: C:\Users\Admin\AppData\Local\npm-cache\_logs\2024-12-16T03_51_51_284Z-debug-0.log

通常是本地npm设置了代理导致的。 检查本地npm配置:

npm config list

出现如下配置错误

npm-config-list.png

如果在npm list 中出现下面的代理配置删除

https-proxy = "http://127.0.0.1:7890"
proxy = "http://127.0.0.1:7890"

使用如下命令删除配置

npm config delete proxy
npm config delete https-proxy

再次重启 verdaccio 即可正常使用。

npm publish 发布不成功

执行npm publish 命令后,提示如下错误:

npm ERR! code ECONNRESET
npm ERR! syscall read
npm ERR! errno ECONNRESET
npm ERR! network request to http://localhost:4873/element-plus-kit failed, reason: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network request to http://localhost:4873/element-plus-kit failed, reason: read ECONNRESET
npm ERR! network request to http://localhost:4873/element-plus-kit failed, reason: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network request to http://localhost:4873/element-plus-kit failed, reason: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network request to http://localhost:4873/element-plus-kit failed, reason: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm-publish-error.png 出现以上错误原因是你的网络无法连接到 npm 官网仓库 registry.npmjs.org/ 导致的,

解决方案
  1. 科学上网
  2. 找到 verdaccio 配置文件**/**/verdaccio/config.yaml,修改 uplinks 下的npmjs 的url地址,可将url配置成taobao镜像源
uplinks:
  npmjs:
    url: https://registry.npmmirror.com/  // [!code focus]

再次重启 verdaccio 即可正常使用。