versioned_docs_archived/version-3.x/cli/add.md
Installs a package and any packages that it depends on. By default, any new package is installed as a prod 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 sax@next | Specify tag next |
pnpm add [email protected] | Specify version 3.0.0 |
A package can be installed from different locations:
pnpm add package-name will install the latest version
of package-name from the npm registry.
You may also install packages by:
pnpm add express@nightlypnpm add [email protected]pnpm add express@2 react@">=0.1.0 <0.2.0"There are two ways to install from the local file system:
.tar, .tar.gz, or .tgz)Examples:
pnpm add ./package.tgz
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 start with "http://" or "https://".
Example:
pnpm add https://github.com/indexzero/forever/tarball/v0.5.6
pnpm install <git remote url>
Installs the package from the hosted Git provider, cloning it with Git.
You may install from Git by:
pnpm add kevva/is-positivepnpm add kevva/is-positive#97edff6f525f192a3f83cea1944765f769ae2678pnpm add kevva/is-positive#masterpnpm add kevva/is-positive#semver:^2.0.0This will install one or more packages in your dependencies.
Using --save-dev or -D will install one or more packages in your devDependencies.
Using --save-optional or -O will install one or more packages in your optionalDependencies.
Saved dependencies will be configured with an exact version rather than using pnpm's default semver range operator.
Added in: v3.2.0
Using --save-peer will add one or more packages to peerDependencies and install them as dev dependencies.
Added in: v3.6.0
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.