pnpm install

別名: i

使用 pnpm install 來為專案安裝所有相依性。

Package manifests and archive metadata larger than 64 MiB are rejected.

在 CI 環境中,如果 lockfile 存在但需要更新時,會使安裝失敗。 To allow lockfile updates in CI, run pnpm install --no-frozen-lockfile.

Inside a workspace, pnpm install installs all dependencies in all the projects. 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.

TL;DR#

命令 效果
pnpm i --offline 僅從儲存區離線安裝套件
pnpm i --frozen-lockfile 不更新 pnpm-lock.yaml
pnpm i --lockfile-only 僅更新 pnpm-lock.yaml
pnpm i --dry-run Preview changes without writing

Options for filtering dependencies#

Without a lockfile, pnpm has to create one, and it must be consistent regardless of dependencies filtering, so running pnpm install --prod on a directory without a lockfile would still resolve the dev dependencies, and it would error if the resolution is unsuccessful. The only exception for this rule are link: dependencies.

Without --frozen-lockfile, pnpm will check for outdated information from file: dependencies, so running pnpm install --prod without --frozen-lockfile on an environment where the target of file: has been removed would error.

--prod, -P#

  • 預設值:false
  • 型別:布林值

If true, pnpm will not install any package listed in devDependencies and will remove those insofar they were already installed. 若為 false,pnpm 則會安裝所有在 devDependencies 及 dependencies 中列出的套件。

--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#

Skip installing runtime entries (e.g. Node.js downloaded via devEngines.runtime). The lockfile is left untouched, so frozen installs still validate; only the runtime fetch and bin-linking are skipped. A runtime that an earlier install linked is removed from node_modules.

This is useful in CI matrices where the runtime is provisioned externally (e.g. via pnpm runtime -g set node <version>) before pnpm install runs.

This can also be set with runtime: false in pnpm-workspace.yaml.

Options#

--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#

Force reinstall dependencies: refetch packages modified in store, recreate a lockfile and/or modules directory created by a non-compatible version of 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
  • 型別:布林值

此值為 true 時,pnpm 僅會使用儲存區中可用的套件。如果在本機無法找到套件,則安裝會失敗。

--no-offline#

Allow network requests even when the offline setting is true.

--prefer-offline#

  • 預設值:false
  • 型別:布林值

此值為 true 時不會檢查快取資料是否過時,但將從伺服器請求遺漏的資料。若要強制啟用完全離線模式,請使用 --offline。

--no-prefer-offline#

Don't prefer cached data even when the preferOffline setting is true.

--no-lockfile#

Don't read or generate a pnpm-lock.yaml file.

--lockfile-only#

  • 預設值:false
  • 型別:布林值

使用此選項時,僅更新 pnpm-lock.yaml 與 package.json。不會對 node_modules 目錄寫入任何檔案。

When resolving an unrelated change, pnpm can reuse Git commits already recorded in the lockfile for unchanged direct and transitive dependencies.

--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#

Run a full dependency resolution and report what a real install would change, without writing anything to disk. No lockfile, manifest, or node_modules changes are saved.

A completed dry run exits with code 0, even when it reports that a real install would update the lockfile.

--dry-run cannot be used with a configured pnpr server, because that install path resolves and links through the server.

--fix-lockfile#

自動修復損壞的 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. This protects projects that ship a committed lockfile from a compromised registry, proxy, or republished version substituting attacker-controlled content on a clean machine.

--update-checksums is the narrowly-scoped opt-in for the legitimate case (e.g. a registry rewrote its tarballs and you've verified the new bytes are correct). A warning still prints when the bypass takes effect so the operation is auditable.

--force and pnpm update deliberately do not bypass the integrity check. --frozen-lockfile is unchanged, and --fix-lockfile keeps its documented purpose (filling in missing lockfile entries) and is also not a bypass.

--frozen-lockfile#

  • 預設值:
    • 在非 CI 環境:false
    • 在 CI 環境:當 lockfile 存在時為 true
  • 型別:布林值

此值為 true 時,pnpm 不會產生 lockfile,並且在 lockfile 與清單不同步、需要更新,或 lockfile 不存在時,會使安裝失敗。

此設定值在CI environments中預設為 true。 pnpm detects a CI environment with the same rules as the ci-info package. Set CI=false to turn detection off.

When verifying a locked tarball online, pnpm asks the registry for fresh package metadata once if the cached metadata omits the locked version.

--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.

--minimum-release-age <minutes>#

Added in: v12.23.0

Sets minimumReleaseAge for this run, overriding the configured value. The value is in minutes. As with a configured value, it turns on minimumReleaseAgeStrict unless that setting is configured. A value that is not a non-negative number is an error.

--minimum-release-age-exclude <package-spec>#

Added in: v12.23.0

Sets minimumReleaseAgeExclude for this run, replacing the configured list. Repeat the option to exclude several packages:

pnpm install --minimum-release-age 1440 --minimum-release-age-exclude react --minimum-release-age-exclude webpack@5.98.0

--merge-git-branch-lockfiles#

Merge all git branch lockfiles. Read more about git branch lockfiles.

--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>#

  • 預設值:
    • For TTY stdout: default
    • For non-TTY stdout: append-only
  • Type: default, append-only, ndjson, silent

Allows you to choose the reporter that will log debug info to the terminal about the installation progress.

  • silent - no output is logged to the console, not even fatal errors
  • default - the default reporter when the stdout is TTY
  • append-only - the output is always appended to the end. 不會進行游標操作
  • ndjson - the most verbose reporter. Prints all logs in ndjson format. Fatal error records include the error code. Dependency resolution errors also include the parent packages in pkgsStack.

If you want to change what type of information is printed, use the loglevel setting.

--shamefully-hoist#

  • 預設值:false
  • 型別:布林值

Creates a flat node_modules structure, similar to that of npm or yarn. WARNING: This is highly discouraged.

--ignore-scripts#

  • 預設值:false
  • 型別:布林值

Do not execute any scripts defined in the project package.json and its dependencies.

--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>#

  • Type: 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 or, since v12.23.0, take a comma-separated list:

pnpm install --allow-build=esbuild --allow-build='!core-js'

Pass a git or tarball key in its own --allow-build. A value that contains one is not split at its commas.

The quotes keep a POSIX shell from treating ! as history expansion. In Windows cmd.exe, leave them out.

writes:

pnpm-workspace.yaml
allowBuilds:
  esbuild: true
  core-js: false

--filter <package_selector>#

Read more about filtering.

--cpu=<name>#

Override CPU architecture of native modules to install. Acceptable values are same as cpu field of package.json, which comes from process.arch.

--os=<name>#

Override OS of native modules to install. Acceptable values are same as os field of package.json, which comes from process.platform.

--libc=<name>#

Override libc of native modules to install. Acceptable values are same as libc field of package.json.