verdaccio配置生效需确保vscode终端继承npm registry环境变量,否则仍直连官方源;根本原因在于vscode终端不自动加载shell配置文件,且调试器子进程不透传registry设置,应优先检查echo $npm_config_registry和项目级.npmrc。

Verdaccio 本身不修改 npm 行为,但 VSCode 终端若未继承 shell 的 registry 配置,就会绕过代理直接连官方源——这是绝大多数人“配了却没生效”的根本原因。
Verdaccio 启动后 npm install 仍直连 registry.npmjs.org
现象:Verdaccio 已在 localhost:4873 正常运行,npm config get registry 显示 http://localhost:4873,但执行 npm install 时仍卡在 registry.npmjs.org 或报 ETIMEDOUT。
- VSCode 内置终端默认不读取 shell 的
~/.zshrc或~/.bash_profile,哪怕你在 iTerm 里已成功配置npm config set registry http://localhost:4873 - Windows PowerShell 用户需确认是否被策略阻止执行脚本:
Get-ExecutionPolicy -Scope CurrentUser若返回Restricted,则npm config命令可能静默失败 - Verdaccio 默认只代理
public包(即非 scoped 包),如果你装的是@org/pkg,需在config.yaml中显式启用:packages: '@org/*': access: $all proxy: npmjs
VSCode 调试时 nodemon 不走 Verdaccio 代理
现象:命令行下 nodemon index.js 能正确安装依赖并启动,但在 VSCode 里按 F5 启动调试时,require('xxx') 报 Cannot find module。
使用一条命令部署ProbeChain Rydberg测试网代理节点。自动注册为Agent(NodeType=1),免gas,支持macOS/Linux/Windows。触发词:/r
-
launch.json中的env字段未透传NODE_OPTIONS或npm_config_registry,导致子进程(如node或nodemon)无法继承 registry 设置 - 更稳妥的做法是把 registry 写进项目级
.npmrc(与package.json同级),内容为:registry=http://localhost:4873;VSCode 终端和调试器都会优先读取它 - 若用
npm run dev启动,确保scripts.dev是nodemon --exec node index.js而非nodemon index.js,否则nodemon自己会调用npm install,而该调用不继承当前 shell 环境变量
Verdaccio 缓存命中但 package.json 里版本号没变
现象:改了依赖包的 minor 版本(如从 1.2.0 升到 1.3.0),Verdaccio 日志显示 cache hit,但 node_modules/xxx/package.json 仍是旧版。
- npm 默认启用
package-lock.json锁定精确版本,即使 registry 返回新版本,npm install仍按 lockfile 还原——这不是 Verdaccio 的问题,而是 npm 机制 - 验证是否真走代理:删掉
node_modules和package-lock.json,执行npm install --no-package-lock,观察 Verdaccio 日志是否有fetch记录 - Verdaccio 的缓存路径默认在
~/.verdaccio/storage,若磁盘满或权限不足,它会退化为仅代理不缓存,此时日志会出现error --- unable to create directory
真正难排查的不是 Verdaccio 配置本身,而是 VSCode 终端环境变量与项目本地配置之间的三层隔离:shell 配置、VSCode 启动方式、.npmrc 作用域优先级。别急着改 config.yaml,先在 VSCode 终端里跑一遍 echo $NPM_CONFIG_REGISTRY 和 cat .npmrc,答案通常就藏在这两行输出里。










