Skip to main content
Version: 9.x

pnpm install

别名:i

¥Aliases: i

pnpm install 用于安装项目的所有依赖。

¥pnpm install is used to install all dependencies for a project.

在 CI 环境中,如果存在锁定文件但需要更新,则安装会失败。

¥In a CI environment, installation fails if a lockfile is present but needs an update.

workspace 内,pnpm install 安装所有项目中的所有依赖。如果要禁用此行为,请将 recursive-install 设置设置为 false

¥Inside a workspace, pnpm install installs all dependencies in all the projects. If you want to disable this behavior, set the recursive-install setting to false.

长话短说

¥TL;DR

命令意义
pnpm i --offline仅从存储离线安装
pnpm i --frozen-lockfilepnpm-lock.yaml 未更新
pnpm i --lockfile-only仅更新了 pnpm-lock.yaml

选项

¥Options

--force

强制重新安装依赖:重新获取存储中修改的包,重新创建由不兼容版本的 pnpm 创建的锁定文件和/或模块目录。安装所有可选依赖,即使它们不满足当前环境(cpu、操作系统、arch)。

¥Force reinstall dependencies: refetch packages modified in store, recreate a lockfile and/or modules directory created by a non-compatible version of pnpm. Install all optionalDependencies even they don't satisfy the current environment(cpu, os, arch).

--offline

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

如果是 true,pnpm 将仅使用存储中已有的软件包。如果在本地找不到包,安装将会失败。

¥If true, pnpm will use only packages already available in the store. If a package won't be found locally, the installation will fail.

--prefer-offline

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

如果是 true,将绕过缓存数据的过时检查,但将从服务器请求丢失的数据。要强制完全离线模式,请使用 --offline

¥If true, staleness checks for cached data will be bypassed, but missing data will be requested from the server. To force full offline mode, use --offline.

--prod, -P

  • 默认:

    ¥Default:

    • If NODE_ENV is production:true

    • 如果 NODE_ENV 不是 productionfalse

      ¥If NODE_ENV is not production: false

  • 类型:布尔值

    ¥Type: Boolean

如果设置,pnpm 将忽略 NODE_ENV 并使用此布尔值来确定环境。

¥If set, pnpm will ignore NODE_ENV and instead use this boolean value for determining the environment.

如果是 true,pnpm 将不会安装 devDependencies 中列出的任何软件包,并将删除那些已安装的软件包。如果是 false,pnpm 将安装 devDependenciesdependencies 中列出的所有软件包。

¥If true, pnpm will not install any package listed in devDependencies and will remove those insofar they were already installed. If false, pnpm will install all packages listed in devDependencies and dependencies.

--dev, -D

仅安装 devDependencies,并删除已安装的 dependencies,无论 NODE_ENV 为何。

¥Only devDependencies are installed and dependencies are removed insofar they were already installed, regardless of the NODE_ENV.

--no-optional

optionalDependencies 未安装。

¥optionalDependencies are not installed.

--lockfile-only

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

使用时,仅更新 pnpm-lock.yamlpackage.json。没有任何内容写入 node_modules 目录。

¥When used, only updates pnpm-lock.yaml and package.json. Nothing gets written to the node_modules directory.

--fix-lockfile

自动修复损坏的锁定文件条目。

¥Fix broken lockfile entries automatically.

--frozen-lockfile

  • 默认:

    ¥Default:

    • 对于非 CI:false

      ¥For non-CI: false

    • 对于 CI:true,如果存在锁定文件

      ¥For CI: true, if a lockfile is present

  • 类型:布尔值

    ¥Type: Boolean

如果 true,pnpm 不会生成锁定文件,并且如果锁定文件与清单不同步/需要更新或不存在锁定文件,则安装失败。

¥If true, pnpm doesn't generate a lockfile and fails to install if the lockfile is out of sync with the manifest / an update is needed or no lockfile is present.

该设置在 持续集成环境 中默认为 true。以下代码用于检测 CI 环境:

¥This setting is true by default in CI environments. The following code is used to detect CI environments:

https://github.com/watson/ci-info/blob/44e98cebcdf4403f162195fbcf90b1f69fc6e047/index.js#L54-L61
exports.isCI = !!(
env.CI || // Travis CI, CircleCI, Cirrus CI, GitLab CI, Appveyor, CodeShip, dsari
env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
env.BUILD_NUMBER || // Jenkins, TeamCity
env.RUN_ID || // TaskCluster, dsari
exports.name ||
false
)

--merge-git-branch-lockfiles

合并所有 git 分支锁定文件。阅读有关 git 分支锁定文件的更多信息。

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

--reporter=<name>

  • 默认:

    ¥Default:

    • 对于 TTY 标准输出:default

      ¥For TTY stdout: default

    • 对于非 TTY 标准输出:append-only

      ¥For non-TTY stdout: append-only

  • 类型:default, append-only, ndjson, silent

    ¥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 - 控制台没有记录任何输出,甚至没有致命错误

    ¥silent - no output is logged to the console, not even fatal errors

  • default - 当标准输出为 TTY 时的默认报告者

    ¥default - the default reporter when the stdout is TTY

  • append-only - 输出总是附加到末尾。不执行光标操作

    ¥append-only - the output is always appended to the end. No cursor manipulations are performed

  • ndjson - the most verbose reporter.以 ndjson 格式打印所有日志

    ¥ndjson - the most verbose reporter. Prints all logs in ndjson format

如果你想更改打印信息的类型,请使用 loglevel 设置。

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

--use-store-server

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

危险

已弃用的功能

¥Deprecated feature

在后台启动存储服务器。安装完成后,存储服务器将继续运行。要停止存储服务器,请运行 pnpm server stop

¥Starts a store server in the background. The store server will keep running after installation is done. To stop the store server, run pnpm server stop

--shamefully-hoist

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

创建扁平 node_modules 结构,类似于 npmyarn。WARNING:这是非常不鼓励的。

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

--ignore-scripts

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

不要执行项目 package.json 及其依赖中定义的任何脚本。

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

--filter <package_selector>

警告

过滤器当前无法在 v8 默认配置下正常工作,你必须隐式将 dedupe-peer-dependents 设置为 false 才能正常工作。更多信息和进展请参阅 #6300

¥Filter currently does not work properly with v8 default config, you have to implicitly set dedupe-peer-dependents to false to have that work. For more info and progress please refer to #6300

了解有关过滤的更多信息。

¥Read more about filtering.

--resolution-only

重新运行解析:对于打印出对等依赖问题很有用。

¥Re-runs resolution: useful for printing out peer dependency issues.