跳到主内容
版本:9.x

pnpm install

Aliases: i

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

在CI环境中, 如果存在需要更新的 lockfile 会安装失败.

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.

摘要:

CommandMeaning
pnpm i --offline仅从 store 中离线下载
pnpm i --frozen-lockfilepnpm-lock.yaml is not updated
pnpm i --lockfile-onlyOnly pnpm-lock.yaml is updated

配置项

--force

强制重新安装依赖:重新获取并修改缓存中的包,由不兼容版本的 pnpm重新创建的lock文件和(或)模块目录。 安装所有 optionalDependencies,即使它们不满足当前环境(cpu、os、arch)。

--offline

  • Default: false
  • Type: Boolean

If true, pnpm will use only packages already available in the store. 如果缓存中没有找不到这个包,那么就会安装失败。

--prefer-offline

  • Default: false
  • Type: Boolean

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

  • 默认值:
    • If NODE_ENV is production: true
    • If NODE_ENV is not production: false
  • 类型:Boolean

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

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

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

--no-optional

optionalDependencies are not installed.

--lockfile-only

  • Default: false
  • Type: Boolean

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

--fix-lockfile

自动修复损坏的 lock 文件入口。

--frozen-lockfile

  • 默认值:
    • For non-CI: false
    • For CI: true, if a lockfile is present
  • Type: Boolean

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.

This setting is true by default in CI environments. 以下代码用于检测 CI 环境:

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 分支上的 lockfiles。 Read more about git branch lockfiles.

--reporter=<name>

  • 默认值:
    • For TTY stdout: default
    • For non-TTY stdout: append-only
  • Type: default, append-only, ndjson, silent

允许您选择向终端输出安装进度的试信息的报告程序。

  • 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

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

--use-store-server

  • Default: false
  • Type: Boolean
警告

Deprecated feature

在后台启动 store server. store server 会在安装完成后持续运行. To stop the store server, run pnpm server stop

--shamefully-hoist

  • Default: false
  • Type: Boolean

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

--ignore-scripts

  • Default: false
  • Type: Boolean

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

--filter <package_selector>

warning

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

重新进行解析:对于打印出peer dependency 问题很有用。