其它设置
savePrefix#
- 默认值:'^'
- 类型:‘^'、'~'、"、'='
配置软件包在 package.json 文件中的版本前缀。
例如,如果一个包的版本为 1.2.3,默认情况下它的版本设置为 ^1.2.3 允许对该包进行小版本升级,但在 pnpm config set save-prefix='~' 之后,它将设置为 ~1.2.3 仅允许补丁版本升级。
With =, newly added dependencies are saved with an
explicit = operator (=1.2.3), which pins the exact version. pnpm update
在更新这种固定时会保留 = 符号。
当添加的包具有指定的范围时,将忽略此设置。例如,pnpm add foo@2 将会把 package.json 中的 foo 设置为 2,而忽略 save-prefix 的值。
saveExact#
- 默认值: false
- 类型:Boolean
When set to true, pnpm add saves the resolved version without a range
operator, as the --save-exact CLI option does.
saveTypes#
添加于:v12.6.0
- 默认值: false
- 类型:Boolean
When set to true, pnpm add saves available @types/* packages in
devDependencies alongside registry dependencies. Packages that declare bundled
TypeScript types are skipped.
saveTypes: true
You can also pass it as a CLI flag: pnpm add --save-types express.
tag#
- 默认值:latest
- 类型:字符串
If you pnpm add a package and you don't provide a specific version, pnpm
saves the first of these that exists:
- A
catalog:reference, if the catalog pnpm saves to lists the package. - The range that every other workspace project declaring the package uses.
pnpm skips this step when the projects declare different ranges or one of
them uses a protocol, such as
workspace:. - The range a matching override sets.
- The version registered under the tag from this setting.
pnpm publish also publishes under this tag when --tag is not passed.
globalDir#
- 默认值:
- If the $PNPM_HOME env variable is set, then $PNPM_HOME/global
- 如果设置了 $XDG_DATA_HOME 环境变量,则为 $XDG_DATA_HOME/pnpm/global
- 在 Windows 上:~/AppData/Local/pnpm/global
- 在 macOS 上:~/Library/pnpm/global
- 在 Linux 上:~/.local/share/pnpm/global
- 类型:路径
指定储存全局依赖的目录。 pnpm stores the packages
in a v11 subdirectory of this directory.
globalBinDir#
- 默认值:
- If the $PNPM_HOME env variable is set, then $PNPM_HOME/bin
- 如果设置了 $XDG_DATA_HOME 环境变量,则为 $XDG_DATA_HOME/pnpm/rc
- 在 Windows 上:~/AppData/Local/pnpm
- 在 macOS 上:~/Library/pnpm/bin
- 在Linux上:~/.local/share/pnpm/bin
- 类型:路径
允许设置全局安装包的 bin 文件的目标目录。
globalShims#
添加于:v12.0.0-rc.2
- 默认值:{ node: auto, deno: auto, bun: auto }
- 类型:Boolean,Object
Controls which globally installed packages get project-aware shims: global commands that run the version the current project asks for instead of the globally installed one.
该设置是一个从包名到策略的映射。键是提供该命令的包名称,而非命令本身,因此为 typescript 设置的条目会覆盖它的 tsc 可执行文件。
globalShims:
node: auto
deno: false
typescript: prompt
支持的策略包括:
| 值 | 行为 |
|---|---|
auto(或 true) |
若候选项已通过发布者签名验证,则自动切换;否则需要确认一次。 |
prompt |
所有候选项都要经过确认环节,包括已通过签名验证的候选项。回答会被记住,因此对每个项目与每个候选项只会询问一次,而不会在每次运行时都询问。 |
always |
总是切换,从不询问。适用于 CI,因为在那里出现提示会回退到全局版本。 |
false |
对该包禁用项目感知填充程序。 |
自 v12.0.0-rc.6 起,有两个命令会替你写入条目:pnpm shim add <pkg> 记录它为其链接填充程序的包,而全局安装包管理器(pnpm add -g yarn)会记录该包管理器,使其遵循项目的固定版本。 Neither overwrites an entry you set yourself, including false, and including a globalShims: false that turns every shim off.
Layers merge key by key over the built-in defaults, so a single entry can change one package without restating the rest. globalShims: { bun: false } leaves node and deno at auto.
标量简写不会合并,而是替换整个映射:globalShims: false 会禁用所有项目感知填充程序,globalShims: true 则恢复为默认值。
警告
该设置仅从项目无法写入的位置读取:全局配置文件、pnpm 主目录中的 pnpm-workspace.yaml,以及 PNPM_CONFIG_GLOBAL_SHIMS 环境变量(一个 JSON 值),并按该顺序应用。 A project's own pnpm-workspace.yaml is ignored. Otherwise a repository could grant itself the right to run its own binaries in place of your global ones.
Disabling a package, or changing its policy, takes effect on the very next command. The setting is re-read on each dispatch, so no reinstall is needed.
而新启用某个包则属于例外。 pnpm 在安装时决定为哪些可执行文件写入调度填充程序,因此若某个包在被禁用期间就已全局安装,需要重新安装才能应用这一变更:
pnpm add -g typescript
若要在单次调用中绕过调度,请设置 PNPM_SHIM_BYPASS=1:
PNPM_SHIM_BYPASS=1 node --version
注意
项目感知填充程序属于 pnpm v12 的功能,v11 中不可用。
npmrcAuthFile#
- 默认值:~/.npmrc
- 类型:路径
包含注册源身份验证令牌的文件路径。默认情况下,pnpm 从 ~/.npmrc 读取身份验证令牌作为注册源身份验证的备用方案。使用此设置来指向不同的文件。
此设置无法在项目级的 pnpm-workspace.yaml 中配置;请在全局配置文件中,或通过 --npmrc-auth-file 命令行选项,又或是通过 PNPM_CONFIG_NPMRC_AUTH_FILE 环境变量进行设置(系统也会兼容 npm 风格的 NPM_CONFIG_USERCONFIG 作为备选)。相对路径是相对于工作目录进行解析的。
stateDir#
- 默认值:
- 如果设置了 $XDG_STATE_HOME 环境变量,则为 $XDG_STATE_HOME/pnpm
- 在 Windows 上:~/AppData/Local/pnpm-state
- On macOS and Linux: ~/.local/state/pnpm
- 类型:路径
The directory where pnpm stores machine-level state, including the update checker's pnpm-state.json file.
Since v12.5.0, task concurrency groups also store their shared slot files under stateDir/run-slots. Processes must use the same stateDir to share group limits. Different state directories create independent slot pools, so their combined task count can exceed the configured limit.
Set stateDir in the global configuration file or on the command line. It is ignored in project pnpm-workspace.yaml files.
cacheDir#
- 默认值:
- 如果设置了 $XDG_CACHE_HOME 环境变量,则为 $XDG_CACHE_HOME/pnpm
- 在 Windows 上:~/AppData/Local/pnpm-cache
- 在 macOS 上:~/Library/Caches/pnpm
- 在 Linux 上:~/.cache/pnpm
- 类型:路径
缓存的位置(包含包元数据、dlx 缓存以及部分安装验证结果)。
与存储一样,缓存目录仅供相互信任的用户、作业和进程共享。如果你配置或恢复了共享的 cacheDir,请通过文件系统权限对其进行保护,以防止不受信任的用户向其写入数据。
useStderr#
- 默认值: false
- 类型:Boolean
当为 true 时,所有输出都写入 stderr。
updateNotifier#
- 默认值:true
- 类型:Boolean
设置为 false 以便在使用较旧版本的 pnpm 时关闭更新通知。
pnpm install and pnpm add check at most once a day, and print how to get the
newer version. The check is skipped in CI and with --offline or
--prefer-offline.
preferSymlinkedExecutables#
- 默认值:当 node-linker 设置为 hoisted 且系统为 POSIX 时为 true
- 类型:Boolean
创建指向 node_modules/.bin 中可执行文件的符号链接,而不是命令 shims。在 Windows 上,此设置将被忽略,因为只有命令 shims 起作用。
ignoreCompatibilityDb#
- 默认值: false
- 类型:Boolean
在安装过程中,某些包的依赖关系会被自动打补丁。如果你想禁用此功能,请将此配置设置为 true。
The patches are applied from Yarn's @yarnpkg/extensions package, plus pnpm's
own curated entries.
Since v12.0.0, the database no longer carries entries that were derived from
static analysis of published packages. Those entries named packages a dependent
imported only for its types. Adding them was at best unnecessary and at worst
broke the dependent: @typescript-eslint/types gained a typescript dependency
resolved to the newest release, which put TypeScript 7 under older
@typescript-eslint versions and made ESLint fail with Cannot read properties of undefined (reading 'Intrinsic').
resolutionMode#
- Default: highest
- 类型:highest、time-based、lowest-direct
当 resolutionMode 设置为 time-based,依赖关系将按以下方式解析:
- 直接依赖项将解析为最低版本。因此,如果依赖项中有
foo@^1.1.0,则将安装1.1.0。 - Subdependencies will be resolved from versions that were published no later than one hour after the newest direct dependency. If none of those versions satisfies a subdependency's range, pnpm installs the lowest version that does.
If minimumReleaseAge is also set, pnpm resolves subdependencies against whichever of the two cutoffs is earlier. If no version published before that cutoff satisfies a subdependency's range, pnpm installs the lowest matching version that is older than the minimumReleaseAge cutoff. If every matching version is newer than the minimumReleaseAge cutoff, pnpm falls back to the lowest matching version, and minimumReleaseAgeStrict decides whether pnpm installs it or fails. Only the minimumReleaseAge cutoff decides which versions pnpm reports as too new. A version that is newer than the time-based cutoff but older than the minimumReleaseAge cutoff is installed without a warning or error.
使用此解析模式的安装,具有热高速缓存的速度更快。它还减少了子依赖项劫持的机会,因为只有更新直接依赖项,子依赖项才会更新。
此解析模式仅适用于 npm 的 完整元数据。因此,在某些场景中,速度较慢。但是,如果你使用 Verdaccio v5.15.1 或更高版本,则可以将 registrySupportsTimeField 设置为 true,速度会非常快。
当 resolutionMode 设置为 lowest-direct 时,直接依赖项将解析为其最低版本。
在此,只有 package.json 中声明的依赖才被视为直接依赖。由 autoInstallPeers 添加的 peer 依赖并非项目声明的依赖,因此会像子依赖那样解析:解析到满足 peer 范围的最高版本;在 time-based 模式下则解析到发布日期截止范围内最高的版本。
registrySupportsTimeField#
- 默认值: false
- 类型:Boolean
如果你使用的注册表在缩略元数据中返回了 "time" 字段,请将此设置为 true。 Verdaccio 从 v5.15.1 起支持此功能,某些注册源代理亦如此。
This can also be declared per registry, through the supportsTimeField field of a registry declaration. 注册源自身的声明优先;而项目未描述的所有注册源均以此设置为准。
extendNodePath#
- 默认值:true
- 类型:Boolean
当为 true 时,pnpm 会在命令 shims
中设置 NODE_PATH 环境变量(在 node_modules/.bin 中创建的包装脚本)。当 false 时,NODE_PATH 未设置。
为什么需要这样做#
pnpm 的[孤立的 node_modules 布局]意味着包只能访问其声明的依赖关系。但是,当 CLI 工具通过命令 shim 运行时,一些
库(特别是 import-local,被 jest、eslint 等使用)会从当前工作目录而不是从二进制文件自身的
位置解析模块。 Since the working directory is the project root, not the package inside
the virtual store, the standard node_modules resolution from the CWD won't
find the binary's transitive dependencies.
为了弥合这一差距,pnpm 在 NODE_PATH 中包含了两种类型的路径:
- The package's own dependencies directory (e.g.,
.pnpm/pkg@version/node_modules). This allows CWD-based resolution to find the correct versions of the package's sibling dependencies. - The hoisted
node_modulesdirectory (e.g.,.pnpm/node_modules). This is the directory where hoisted packages are placed whenhoistPatternis set. Node.js 无法通过其标准解析算法发现此目录,因此必须通过NODE_PATH提供。
当启用 enableGlobalVirtualStore 时,NODE_PATH 也至关重要。使用全局虚拟存储时,软件包是从项目外部的中央位置
进行符号链接的,因此 Node.js 从二进制文件的实际路径向上遍历 node_modules 的标准方法不会到达项目自己的 node_modules 或其提升的依赖项。在这种情况下,NODE_PATH 必须包含项目的根
node_modules,以及在 node_modules/.pnpm/node_modules 的提升目录
以确保解析正确。
何时禁用#
如果你确定你的项目中没有一个 CLI 工具从工作目录解析模块,且你没有使用全局虚拟存储,你可以将其设置为 false 。禁用它后,指令垫片会稍微简单一些。
deployAllFiles#
- 默认值: false
- 类型:Boolean
在部署包或安装本地包时,包的所有文件都会被复制。默认情况下,如果软件包在 package.json 中有一个 "files" 字段,那么只会复制列出的文件和目录。
embedReadme#
- 默认值: false
- 类型:Boolean
When set to true, pnpm pack and pnpm publish add the content of the
package's README file to the readme field of the packed package.json, unless
that field is already set. pnpm publish --embed-readme sets it for a single
command.
dedupeDirectDeps#
- 默认值: false
- 类型:Boolean
当设置为 true 时,已符号链接到工作区根 node_modules 目录的依赖项将不会符号链接到子项目 node_modules 目录。
optimisticRepeatInstall#
- 默认值:true
- 类型:Boolean
启用后,将在继续安装之前进行快速检查。这样,重复安装或在项目上安装所有内容都是最新的就会变得更快。
The check compares the manifests, the lockfile, and the patch files by content, so an edit is noticed even when it keeps the file's modification time. A filtered install checks only the selected projects and the workspace projects they depend on.
When the check finds that nothing changed, pnpm skips the install, including the projects' own lifecycle scripts, such as prepare. Set this to false to run those scripts on every install.
requiredScripts#
Scripts listed in this array are required in each project selected by pnpm -r run <script name>. Otherwise, the run fails.
requiredScripts:
- build
enablePrePostScripts#
- 默认值:true
- 类型:Boolean
当 true 时,pnpm 将自动运行任何前/后脚本。因此运行 pnpm foo
将类似于运行 pnpm prefoo pnpm foo pnpm postfoo。
scriptShell#
- 默认值: null
- 类型:路径
使用 pnpm run 命令运行脚本所使用的 shell。
例如,在 Windows 系统上强制使用 Git Bash:
pnpm config set scriptShell "C:\\Program Files\\git\\bin\\bash.exe"
自 v12.4.0 起,pnpm-workspace.yaml 中的相对路径从工作区根目录解析,包括在嵌套包中运行的脚本。像 bash 这样的裸命令名仍会在 PATH 中查找。
shellEmulator#
- 默认值: false
- 类型:Boolean
当为 true 时,pnpm 将使用其内置的跨平台、类 bash 的 shell 来执行脚本。
该选项简化了跨平台运行脚本。例如,默认情况下,下述脚本将在非 POSIX 标准兼容系统下运行失败:
"scripts": {
"test": "NODE_ENV=test node test.js"
}
但是,如果 shellEmulator 设置为 true,它将适用于所有平台。
自 v12.8.0 起,对于 pnpm run 和生命周期脚本,已配置的非空 scriptShell 优先于 shellEmulator。仅当 scriptShell 未设置或为空时,才会运行模拟器。
Parameter expansions such as ${MODE:-dev} read the variable when the command runs. For example, export MODE=prod && echo ${MODE:-dev} prints prod.
注意
Node.js 22 或更高版本支持在没有 pnpm 帮助的情况下运行脚本。对于上面的例子,你可以使用“node --run test”运行“test”脚本。但是,shellEmulator 选项对此没有影响。依赖 POSIX 特性的脚本需要运行 pnpm run 而不是node --run 才能在不兼容 POSIX 的环境中工作。
catalogMode#
Set catalog.mode alongside catalog.entries to choose how pnpm add uses the default catalog. The top-level catalogMode setting accepts the same values. When a file sets both, catalog.mode wins.
- 默认值: manual
- 类型:manual、strict、prefer
控制运行 pnpm add 时是否以及如何将依赖项添加到默认目录中。有三种模式:
- strict - 仅允许来自目录的依赖版本。在目录版本范围之外添加依赖关系会导致错误。
- prefer - 优先使用目录版本,但如果未找到兼容版本,则会退回到直接依赖项。
- manual(默认)——不会自动将依赖项添加到目录中。
自 v12.3.0 起,指定位置而非版本的说明符永远不会被移入目录:本地路径、本地 tarball、tarball URL 和 workspace:\<path> 范围会保留在声明它们的 package.json 中。此类说明符相对于其自身项目解析,因此一个目录条目无法对引用它的每个项目都表示相同的目录。
catalog.defaultSaveTarget#
Set catalog.defaultSaveTarget alongside catalog.entries to choose where pnpm add saves a dependency. Use default for the default catalog or supply a named catalog. The command-line flags --save-catalog and --save-catalog-name take precedence.
catalog:
entries: {}
mode: prefer
defaultSaveTarget: tools
The top-level saveCatalogName setting continues to work. When a file sets both, catalog.defaultSaveTarget wins. If you define the default catalog under catalogs.default, use the top-level settings or move its entries to catalog.entries before using the nested settings.
ci#
- 默认值:true(当环境被检测为 CI 时)
- 类型:Boolean
此设置明确告诉 pnpm 当前环境是否为 CI(持续集成)环境。
In CI, frozenLockfile defaults to true when a lockfile is present, the default reporter is append-only, and the update check is skipped.
This setting is ignored in project pnpm-workspace.yaml files.
catalog.entries and catalog.unused#
Put the default catalog's packages under catalog.entries to configure cleanup alongside them. Use entries: {} for an empty map. Without entries, a key named unused refers to a package.
catalog:
unused: prune
entries:
example-tool: ^2.0.0
catalog.unused accepts ignore (the default) or prune. Pruning covers the default catalog and all named catalogs in catalogs. When a file sets both catalog.unused and catalogPrune, catalog.unused wins.
catalogPrune#
- 默认值: false
- 类型:Boolean
当设置为 true 时,pnpm 将在安装期间删除未使用的目录条目。
cleanupUnusedCatalogs 是该设置已弃用的名称,但仍可继续使用;若两者同时设置,则以 catalogPrune 为准。
macosBackup.excludeModulesDir#
添加于:v12.6.0
- 默认值: false
- 类型:Boolean
When set to true on macOS, pnpm marks newly created node_modules, virtual-store, and similar directories with the com.apple.metadata:com_apple_backup_excludeItem extended attribute, so Time Machine skips them.
Set it in the global configuration file or via the PNPM_CONFIG_MACOS_BACKUP_EXCLUDE_MODULES_DIR environment variable. This setting is ignored in project pnpm-workspace.yaml files and on non-macOS platforms.
macosBackup:
excludeModulesDir: true
macosBackup.excludeStoreDir#
添加于:v12.6.0
- 默认值: false
- 类型:Boolean
When set to true on macOS, pnpm marks newly created package-store directories with the Time Machine exclusion attribute.
Set it in the global configuration file or via the PNPM_CONFIG_MACOS_BACKUP_EXCLUDE_STORE_DIR environment variable. This setting is ignored in project pnpm-workspace.yaml files and on non-macOS platforms.
macosBackup:
excludeStoreDir: true