pnpm doctor

对 pnpm 的安装及其运行环境执行诊断。

pnpm doctor [--offline] [--benchmark] [--json]

每项检查都会报告如何修复其发现的问题,且当任何检查失败时,该命令会以非零状态码退出。警告不会导致命令失败。

✓ Versions: pnpm 12.3.4, Node.js 22.20.0
✓ Install method: pnpm
✓ 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

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.

全局 bin 目录#

检查 pnpm 链接全局可执行文件的目标目录是否在 PATH 中且可写。若它不在 PATH 中,解决办法是运行 pnpm setup。

缓存目录#

检查缓存目录是否可写。

存储目录#

检查存储目录是否可写。 When no store directory is configured, the check runs against the default store.

文件系统#

基于存储卷运作的链接策略包括:引用链接(写时复制)、硬链接和符号链接。 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 不会跳过它。

配置项#

--offline#

跳过需要网络访问的检查。

--benchmark#

还有时间文件系统和安装检查,与每个结果一起报告持续时间。

--json#

将结果报告为 JSON。输出是一个仅含 checks 数组的对象,每个条目都带有 title、status(pass、warn 或 fail),以及可选的 detail、fix 和 durationMs。

{
  "checks": [
    {
      "title": "Filesystem",
      "status": "pass",
      "detail": "available: reflink, hardlink, symlink",
      "durationMs": 3
    }
  ]
}