Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`npm install -g` keeps the `bin` link on the old version after the default Node.js changes

未关闭
#3,279 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@mondaychen 已经在做这个了。

开始于 2026年10月29日。

  • #3283 来自 @mondaychen —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

bug triage: failed
Describe the bug

When Vite+ manages Node.js, npm install -g <pkg> installs the package into the prefix of the active Node.js version. Vite+ then links the package binary into ~/.vite-plus/bin/ and records the owner in ~/.vite-plus/bins/<bin>.json.

When the active Node.js version changes (for example, the latest LTS moves from 24 to 26), I run npm install -g <pkg> again to update the package. npm installs a new copy into the new Node.js prefix and reports success. But the link in ~/.vite-plus/bin/ still points to the copy in the old Node.js prefix. Vite+ shows no message. When I run the command, I get the old version.

Expected: the link points to the copy that npm just installed, or Vite+ tells me that it kept the old link.

Cause: in check_npm_global_install_result, Vite+ replaces an existing link only when a different npm package owns it. When the same package owns it, Vite+ skips it, and it does not compare the link target with the new npm bin directory:

https://github.com/voidzero-dev/vite-plus/blob/7073d613af772874a07f085aa676160131291c57/crates/vp_global_cli/src/shim/dispatch.rs#L287-L313

Possible fix: also replace the link when the same package owns it but the link target is not in the current npm bin directory. Write the new nodeVersion to the bin config, and print a line such as Relinked 'agent-browser' to Node.js 26.13.0 (was 24.15.0).

I can submit a PR for this fix.

Related: #1986 (general discussion about npm install -g and Node.js version management).

Reproduction

No repository is necessary. This is global CLI behavior. See the steps below.

Steps to reproduce
# 1. Install a package with an older default Node.js version
vp env default 24
npm install -g cowsay          # Answer "Y" to create the link
ls -l ~/.vite-plus/bin/cowsay  # -> .../js_runtime/node/24.x.y/bin/cowsay

# 2. Change the default Node.js version, then install the package again
vp env default 26
npm install -g cowsay          # npm reports success; Vite+ prints nothing
ls -l ~/.vite-plus/bin/cowsay  # Still -> .../node/24.x.y/bin/cowsay
cat ~/.vite-plus/bins/cowsay.json   # "nodeVersion" is still 24.x.y

# The new copy exists, but the link does not use it
ls ~/.vite-plus/js_runtime/node/26.*/lib/node_modules/cowsay

Workaround: remove the link (rm ~/.vite-plus/bin/cowsay), then run npm install -g cowsay again; or run vp install -g instead of npm install -g.

On my machine, 7 links point to old Node.js versions (24.15.0, 24.18.0, 24.21.0), while the active version is 26.13.0.

System Info
$ vp env current
Environment:
  Version  26.13.0
  Source   lts

Tool Paths:
  node  /Users/user/.vite-plus/js_runtime/node/26.13.0/bin/node
  npm   /Users/user/.vite-plus/js_runtime/node/26.13.0/bin/npm
  npx   /Users/user/.vite-plus/js_runtime/node/26.13.0/bin/npx

$ vp --version
vp v0.2.1

Local vite-plus:
  vite-plus  Not found

Environment:
  Package manager  Not found
  Node.js          v26.13.0

macOS, npm 10.9.9. The code at the link above is from current main (7073d613), so the bug is also on main.

Used Package Manager

npm

主要语言
Rust
星标
6.5k
派生
296
平均合并
1 天 2 小时
30 天内合并 PR
230

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/vite-plus 的其他 Issue

查看 voidzero-dev/vite-plus 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。