pnpm add <pkg>
En esta página
- TL;DR#
- Supported package sources#
- Options#
- --save-prod, -P, -p#
- --save-dev, -D, -d#
- --save-optional, -O, -o#
- --save-exact, -E, -e#
- --save-peer#
- --save-catalog#
- --save-catalog-name <catalog_name>#
- --config#
- --ignore-workspace-root-check#
- --global, -g#
- --workspace#
- --allow-build#
- --filter <package_selector>#
Installs a package and any packages that it depends on. By default, any new package is installed as a production dependency.
TL;DR#
| Command | Meaning |
|---|---|
pnpm add sax |
Save to dependencies |
pnpm add -D sax |
Save to devDependencies |
pnpm add -O sax |
Save to optionalDependencies |
pnpm add -g sax |
Install package globally |
pnpm add sax@next |
Install from the next tag |
pnpm add sax@3.0.0 |
Specify version 3.0.0 |
Supported package sources#
pnpm supports installing packages from various sources. See the Supported package sources page for detailed documentation on:
- npm registry
- JSR registry
- Workspace packages
- Local file system (tarballs and directories)
- Remote tarballs
- Git repositories (with semver, subdirectories, and more)
Options#
--save-prod, -P, -p#
Install the specified packages as regular dependencies.
--save-dev, -D, -d#
Install the specified packages as devDependencies.
--save-optional, -O, -o#
Install the specified packages as optionalDependencies.
--save-exact, -E, -e#
Saved dependencies will be configured with an exact version rather than using pnpm's default semver range operator.
--save-peer#
Using --save-peer will add one or more packages to peerDependencies and
install them as dev dependencies.
--save-catalog#
Added in: v10.12.1
Save the new dependency to the default catalog.
--save-catalog-name <catalog_name>#
Added in: v10.12.1
Save the new dependency to the specified catalog.
--config#
Added in: v10.8.0
Save the dependency to configDependencies.
--ignore-workspace-root-check#
Adding a new dependency to the root workspace package fails, unless the
--ignore-workspace-root-check or -w flag is used.
For instance, pnpm add debug -w.
--global, -g#
Install a package globally. See Global Packages for details.
Each space-separated package is installed into its own isolated directory. To bundle several packages into a single isolated install (so they share dependencies and are removed together), pass them as a comma-separated list, e.g. pnpm add -g eslint,prettier.
--workspace#
Only adds the new dependency if it is found in the workspace.
--allow-build#
Added in: v10.4.0
A list of package names that are allowed to run postinstall scripts during installation.
Example:
pnpm --allow-build=esbuild add my-bundler
This will run esbuild's postinstall script and also add it to the allowBuilds field of pnpm-workspace.yaml. So, esbuild will always be allowed to run its scripts in the future.