versioned_docs_archived/version-9.x/cli/add.md
Installs a package and any packages that it depends on. By default, any new package is installed as a production dependency.
| 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 [email protected] | Specify version 3.0.0 |
pnpm add package-name will install the latest version of package-name from
the npm registry by default.
If executed in a workspace, the command will first try to check whether other projects in the workspace use the specified package. If so, the already used version range will be installed.
You may also install packages by:
pnpm add express@nightlypnpm add [email protected]pnpm add express@2 react@">=0.1.0 <0.2.0"Note that when adding dependencies and working within a workspace, packages
will be installed from the configured sources, depending on whether or not
link-workspace-packages is set, and use of the
workspace: range protocol.
There are two ways to install from the local file system:
.tar, .tar.gz, or .tgz)Examples:
pnpm add ./package.tar.gz
pnpm add ./some-directory
When you install from a directory, a symlink will be created in the current
project's node_modules, so it is the same as running pnpm link.
The argument must be a fetchable URL starting with "http://" or "https://".
Example:
pnpm add https://github.com/indexzero/forever/tarball/v0.5.6
pnpm add <git remote url>
Installs the package from the hosted Git provider, cloning it with Git.
You may install packages from Git by:
pnpm add kevva/is-positive
pnpm add kevva/is-positive#97edff6f525f192a3f83cea1944765f769ae2678
pnpm add kevva/is-positive#master
pnpm add zkochan/is-negative#heads/canary
pnpm add zkochan/is-negative#2.0.1
pnpm add andreineculau/npm-publish-git#v0.0.7
You can specify version (range) to install using the semver: parameter. For example:
pnpm add zkochan/is-negative#semver:1.0.0
pnpm add andreineculau/npm-publish-git#semver:v0.0.7
pnpm add kevva/is-positive#semver:^2.0.0
pnpm add andreineculau/npm-publish-git#semver:<=v0.0.7
You may also install just a subdirectory from a Git-hosted monorepo using the path: parameter. For instance:
pnpm add RexSkz/test-git-subdir-fetch#path:/packages/simple-react-app
If you want to be more explicit or are using alternative Git hosting, you might want to spell out full Git URL:
# git+ssh
pnpm add git+ssh://[email protected]:zkochan/is-negative.git#2.0.1
# https
pnpm add https://github.com/zkochan/is-negative.git#2.0.1
You can use a protocol shorthand [provier]: for certain Git providers:
pnpm add github:zkochan/is-negative
pnpm add bitbucket:pnpmjs/git-resolver
pnpm add gitlab:pnpm/git-resolver
If [provider]: is omited, it defaults to github:.
It is possible to combine multiple parameters by separating them with &. This can be useful for forks of monorepos:
pnpm add RexSkz/test-git-subdir-fetch.git#beta&path:/packages/simple-react-app
Installs from the beta branch and only the subdirectory at /packages/simple-react-app.
Install the specified packages as regular dependencies.
Install the specified packages as devDependencies.
Install the specified packages as optionalDependencies.
Saved dependencies will be configured with an exact version rather than using pnpm's default semver range operator.
Using --save-peer will add one or more packages to peerDependencies and
install them as dev dependencies.
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.
Install a package globally.
Only adds the new dependency if it is found in the workspace.