pnpm doctor
对 pnpm 的安装及其运行环境执行诊断。
pnpm doctor [--offline] [--benchmark] [--json]
每项检查都会报告如何修复其发现的问题,且当任何检查失败时,该命令会以非零状态码退出。警告不会导致命令失败。
✓ Versions: pnpm 12.3.4, Node.js 22.20.0
✓ Install method: pnpm
✓ Node.js on PATH: /Users/example/.local/share/fnm/node-versions/v22.20.0/installation/bin/node
✓ Script shell: scripts run in /bin/sh (/bin/bash), package executables in /bin/sh (/bin/bash)
✓ Global bin directory: /Users/example/Library/pnpm/bin
✓ Cache directory: /Users/example/Library/Caches/pnpm
✓ Store directory: /Users/example/Library/pnpm/store/v11
✓ Filesystem: available: reflink, hardlink, symlink
✓ Registry connectivity: https://registry.npmjs.org/ (128ms)
✓ Install smoke test: offline "file:" install linked its dependency
✓ Lifecycle scripts: an install script ran /Users/example/.local/share/fnm/node-versions/v22.20.0/installation/bin/node, a script in /Users/example/my-project ran /Users/example/.local/share/fnm/node-versions/v22.20.0/installation/bin/node
All checks passed
检查#
版本#
报告运行的 pnpm 和 Node.js 版本。
安装方法#
Reports pnpm as the install method and warns when pnpm is being run by Corepack, which manages the pnpm version itself and makes pnpm self-update unavailable.
It also warns when the pnpm found on PATH is not the one in the global bin directory. This happens when a copy from another installer, such as npm, Homebrew, Volta, or Scoop, comes first on PATH. The warning names that copy. If pnpm recognizes the installer, it gives the command that removes the copy. Otherwise it gives the PATH change that puts the global bin directory first.
Node.js on PATH#
Added in: v12.23.0
Lists the node executables on the PATH pnpm runs with, in lookup order. Lifecycle scripts run the first one, unless a directory pnpm puts ahead of them, such as node_modules/.bin, has its own node. pnpm itself does not need Node.js, but the executables in node_modules/.bin that run JavaScript do.
Warns when there is no node on PATH, and when a node entry is skipped because it is a broken link, not executable, or not a file. A version manager that relinks node while scripts run can leave such an entry behind.
Script shell#
Added in: v12.23.0
Reports the shell that runs scripts: the scriptShell, the built-in shell emulator, or sh. Outside Windows it also reports what /bin/sh is, because /bin/sh starts every executable in node_modules/.bin. On macOS that is the shell /private/var/select/sh links to.
Fails when the shell that runs scripts is not found.
全局 bin 目录#
检查 pnpm 链接全局可执行文件的目标目录是否在 PATH 中且可写。若它不在 PATH 中,解决办法是运行 pnpm setup。
缓存目录#
检查缓存目录是否可写。
存储目录#
检查存储目录是否可写。 When no store directory is configured, the check runs against the default store.
文件系统#
Probes which link strategies work between the store and the project: reflink (copy-on-write), hardlink, and symlink. This is what determines how packages land in node_modules and how fast an install is. A reflink or hardlink is near-free, a plain copy is not.
如果引用链接和硬链接均无法使用,检查程序会发出警告,提示安装过程将回退到复制模式,并建议将存储区放置在与项目相同的文件系统上。
注册源连接性#
向已配置的注册源发送 15 秒超时的 Ping 请求,并报告往返时间。如果无法连接到注册源或注册源返回错误状态,则操作失败;这通常指向网络、代理或身份验证配置方面的问题。
在 --offline 下会被跳过。
安装烟雾测试#
以 file: 依赖的形式,在临时目录中完全离线地安装一个一次性包。这会端到端地测试解析、存储和链接路径,并确认正在运行的二进制文件确实能够执行安装操作。
该检查在构造上始终是离线的,因此 --offline 不会跳过它。
生命周期脚本#
Added in: v12.23.0
Installs a temporary project whose postinstall script calls a dependency's executable, using the configured script shell. It then runs the same executable through pnpm exec in the current project, if there is one. Both go through the executable's node_modules/.bin shim, which has to find node on PATH. The check reports the node each run used.
If a run fails, the report includes the error and, outside Windows, the end of an sh -x trace of the shim. The trace shows the PATH the shim searched and the command it ran. A shim that finds no node is the usual cause of a script failing with exit status 127.
The run in the current project goes through pnpm exec, so the project's pnpmfile and nodeOptions apply to it as they do to pnpm exec. So do the settings passed to pnpm doctor on the command line. It does not install the project's dependencies. With --offline, it runs offline too. The whole check is skipped when there is no node on PATH.
配置项#
--offline#
跳过需要网络访问的检查。
--benchmark#
Also time the filesystem, install, and lifecycle script checks, reporting the duration alongside each result.
--json#
将结果报告为 JSON。输出是一个仅含 checks 数组的对象,每个条目都带有 title、status(pass、warn 或 fail),以及可选的 detail、fix 和 durationMs。
{
"checks": [
{
"title": "Filesystem",
"status": "pass",
"detail": "available: reflink, hardlink, symlink",
"durationMs": 3
}
]
}