pnpm install
别名:i
pnpm install 用于安装项目的所有依赖项。
Package manifests and archive metadata larger than 64 MiB are rejected.
在 CI 环境中, 如果存在锁文件但需要更新,那么安装会失败. To allow lockfile updates in CI, run pnpm install --no-frozen-lockfile.
在 工作空间 内,pnpm install 会安装所有项目的所有依赖项。 If you want to disable this behavior, set the
recursiveInstall setting to false.
When a workspace project changes, unchanged direct dependencies in other projects
keep their locked versions if those versions still satisfy their declared ranges.
Use pnpm update to request dependency updates.
Changes to a workspace package's bin field are linked into its dependents'
node_modules/.bin on the next install, even with --frozen-lockfile and an
unchanged lockfile.
摘要:#
| 命令 | 含义 |
|---|---|
pnpm i --offline |
仅从存储中离线安装 |
pnpm i --frozen-lockfile |
不更新 pnpm-lock.yaml |
pnpm i --lockfile-only |
仅更新 pnpm-lock.yaml |
pnpm i --dry-run |
预览更改而不实际执行写入操作 |
过滤依赖项的选项#
如果没有锁文件,pnpm 必须创建一个,并且无论依赖项如何过滤,它都必须保持一致,因此在没有锁文件的目录上运行 pnpm install --prod 仍然会解析 dev 依赖项,如果解析不成功,则会出错。此规则的唯一例外是 link: 依赖项。
如果没有 --frozen-lockfile,pnpm 将检查 file: 依赖项中的过时信息,因此在 file: 的目标已被删除的环境中,在没有 --frozen-lockfile 的情况下运行 pnpm install --prod 将会出错。
--prod, -P#
- 默认值: false
- 类型:Boolean
If true, pnpm will not install any package listed in devDependencies and will remove
those insofar they were already installed.
如果 false,pnpm 将安装 devDependency 和 dependency 中列出的所有软件包。
--dev, -D#
Only devDependencies are installed and dependencies are removed insofar they
were already installed.
--no-optional#
不安装 optionalDependencies。
--optional#
Install optionalDependencies even when the optional setting excludes them.
--no-runtime#
跳过安装运行时条目(例如通过 devEngines.runtime 下载的 Node.js)。锁定文件保持不变,因此冻结安装仍然有效;只是跳过了运行时获取和二进制链接。 A runtime that an earlier install linked is removed from node_modules.
这在 CI 矩阵中很有用,运行时是在外部配置的(例如,通过 pnpm runtime -g set node <version> ),然后再运行 pnpm install。
This can also be set with runtime: false in pnpm-workspace.yaml.
配置项#
--ignore-workspace#
Install the current project as a standalone project, without discovering a
pnpm-workspace.yaml in a parent directory. The workspace's settings and other
projects do not apply. See the --ignore-workspace global option.
--force#
强制重新安装依赖:重新获取存储中修改的软件包,重新创建由不兼容版本的 pnpm 创建的锁文件和(或)模块目录。 --force also lifts engineStrict.
Since v12.7.0, --force no longer installs optional dependencies whose os, cpu, or libc do not match the host. Set forceIgnoresPlatform to true to install them anyway.
--offline#
- 默认值: false
- 类型:Boolean
如果为 true,pnpm 将仅使用缓存中已有的包。如果本地找不到包, 则会安装失败。
--no-offline#
Allow network requests even when the offline setting is true.
--prefer-offline#
- 默认值: false
- 类型:Boolean
如果为 true,将跳过对缓存数据的过期检查,但会从服务器请求缺失的数据。要强制完全离线模式,请使用 --offline。
--no-prefer-offline#
Don't prefer cached data even when the preferOffline setting is true.
--no-lockfile#
不要读取或生成 pnpm-lock.yaml 文件。
--lockfile-only#
- 默认值: false
- 类型:Boolean
使用时,只更新 pnpm-lock.yaml 和 package.json。不会向 node_modules 目录写入任何内容。
--lockfile-dir <dir>#
The directory in which pnpm-lock.yaml is created. Several projects can share one lockfile. It cannot be combined with --global.
--dry-run#
执行完整的依赖关系解析,并报告实际安装会带来的变更,而不向磁盘写入任何内容。不会保存锁文件、清单或 node_modules 的更改。
即使“预演”报告实际安装会更新锁文件,它在完成后仍会以退出码 0 结束。
--dry-run 无法与已配置的 pnpr 服务器配合使用,因为该安装路径会通过服务器进行解析与链接。
--fix-lockfile#
自动修复损坏的锁文件入口。
--update-checksums#
Re-resolve every locked package and record the integrity the registry reports now in pnpm-lock.yaml. Use it when a registry rewrote its tarballs, or after a registry starts serving tars.
By default, an integrity mismatch is a hard failure: pnpm install exits with ERR_PNPM_TARBALL_INTEGRITY rather than silently re-resolving from the registry and overwriting the locked integrity. 这能保护那些发布时包含已提交锁文件的项目,防止其在干净的机器上受到以下威胁:受损的注册表、代理服务器,或是包含攻击者控制内容的重新发布版本。
--update-checksums 是一项适用范围有限且需显式启用的选项,用于处理特定合理场景(例如,注册源重写了 tarball 文件,而你已确认新的字节数据无误)。当旁路生效时,系统仍会输出警告信息,以便对该操作进行审计。
--force 和 pnpm update 特意不跳过完整性检查。 --frozen-lockfile 保持不变;--fix-lockfile 也维持其既定用途(补全缺失的锁文件条目),且同样不属于绕过机制。
--frozen-lockfile#
- 默认值:
- 对于非 CI 环境:false
- 对于 CI 环境:如果存在 lock 文件,则为 true
- 类型:Boolean
如果设置为 true, pnpm 不会生成锁文件,且如果锁文件跟清单文件不同步、锁文件需要更新或不存在锁文件,则会安装失败。
在 CI 环境 中,该设置默认为 true 。 pnpm detects a CI environment with the same rules as the ci-info package. Set CI=false to turn detection off.
--no-frozen-lockfile#
Allows lockfile updates during installation. This is the inverse of --frozen-lockfile.
--prefer-frozen-lockfile#
Use the existing lockfile without re-resolving, even when the manifest might have changed. The inverse is --no-prefer-frozen-lockfile, which always re-resolves against the registry. See preferFrozenLockfile.
--ignore-manifest-check#
Skip the check that pnpm-lock.yaml is up to date with package.json under --frozen-lockfile. Use it only when you just wrote the lockfile yourself.
--trust-lockfile#
Skip verifying the lockfile against supply-chain policies. --no-trust-lockfile verifies it even when the configuration trusts it. See trustLockfile.
--auto-dedupe#
Deduplicate compatible dependency versions during installation. --no-auto-dedupe turns it off when the configuration turns it on. See autoDedupe.
--merge-git-branch-lockfiles#
合并所有 Git 分支上的锁文件。阅读有关 git 分支锁文件的更多信息。
--merge-git-branch-lockfiles-branch-pattern <glob>#
Merge the git branch lockfiles when the current branch matches the pattern. The option can be repeated. See mergeGitBranchLockfilesBranchPattern.
--reporter=<name>#
- 默认值:
- 对于 TTY 标准输出:default
- 对于非 TTY 标准输出:append-only
- 类型:default, append-only, ndjson, silent
允许你选择向终端输出有关安装进度的调试信息的报告程序。
- silent - 不会向控制台记录任何信息,也不包含致命错误
- default - 标准输出是 TTY 时的默认报告程序
- append-only - 始终向末尾追加输出。不执行任何光标操作
- ndjson - 最详细报告. Prints all logs in ndjson format. Fatal error records include the error code. Dependency resolution errors also include the parent packages in
pkgsStack.
如果要更改打印信息的类型,请使用 loglevel 设置。
--shamefully-hoist#
- 默认值: false
- 类型:Boolean
创建一个扁平的 node_modules 结构,类似于 npm 或 yarn。警告:强烈不建议这么做。
--ignore-scripts#
- 默认值: false
- 类型:Boolean
不执行项目 package.json 及其依赖中定义的任何脚本。
--no-ignore-scripts#
Run lifecycle scripts even when the ignoreScripts setting is true.
--ignore-pnpmfile#
Don't load the hooks in .pnpmfile.cjs, including the pnpmfiles of config dependencies.
--node-linker <linker>#
- 类型:isolated、hoisted、pnp
Override the nodeLinker setting for this install.
--frozen-store#
Open the store read-only and skip all store writes, for a store on a read-only filesystem. Use it with --offline --frozen-lockfile. --no-frozen-store allows store writes when the configuration turns the read-only store on. See frozenStore.
--network-concurrency <number>#
Override the networkConcurrency setting.
--fetch-timeout <ms>#
Override the fetchTimeout setting.
--fetch-warn-timeout-ms <ms>#
Override the fetchWarnTimeoutMs setting.
--fetch-min-speed-ki-bps <number>#
Override the fetchMinSpeedKiBps setting.
--user-agent <string>#
The User-Agent header to send with registry requests.
--pnpr-server <url>#
Override the pnprServer setting.
--allow-build#
Added in: v12.7.0
Allow the named package to run its lifecycle scripts during this install, and
record it in the allowBuilds field of
pnpm-workspace.yaml so it stays allowed. Prefix a name with ! to deny its
scripts instead. The option can be repeated:
pnpm install --allow-build=esbuild --allow-build='!core-js'
The quotes keep a POSIX shell from treating ! as history expansion. In
Windows cmd.exe, leave them out.
writes:
allowBuilds:
esbuild: true
core-js: false
--filter <package_selector>#
--cpu= #
覆盖要安装的本机模块的 CPU 架构。可接受的值与 package.json 中的 cpu 字段相同,这个字段来自 process.arch。
--os=<name>#
覆盖本机的 OS 原生安装。可接受的值与 package.json 中的 os 字段相同,这个字段来自 process.platform。
--libc=<name>#
覆盖要安装的原生模块的 libc。可接受的值与 package.json 中的 libc 字段相同。