pnpm add <pkg>
패키지와 패키지가 의존하는 모든 패키지를 설치합니다. 기본적으로 새 패키지는 프로덕션 의존성으로 설치됩니다.
요약#
| 명령어 | 의미 |
|---|---|
pnpm add sax |
dependencies에 저장 |
pnpm add -D sax |
devDependencies에 저장 |
pnpm add -O sax |
optionalDependencies에 저장 |
pnpm add -g sax |
패키지를 전역으로 설치합니다 |
pnpm add sax@next |
next 태그에서 설치 |
pnpm add sax@3.0.0 |
버전 3.0.0 지정 |
pnpm add lodash@npm:awesome-lodash |
Install awesome-lodash as lodash |
pnpm add crate:serde |
Add a Cargo crate |
pnpm add pypi:httpx |
Add a Python package |
지원되는 패키지 소스#
pnpm은 다양한 소스에서 패키지를 설치하는 것을 지원합니다. 다음 항목에 대한 자세한 문서는 지원되는 패키지 소스 페이지를 참조하세요:
- npm 레지스트리
- JSR 레지스트리
- 워크스페이스 패키지
- 로컬 파일 시스템 (tarball 및 디렉토리)
- 원격 tarball
- Git repository (semver, 하위 디렉토리 등 포함)
- crates.io and PyPI, through the
crate:andpypi:prefixes
Package aliases#
To install an npm package under a different local name, use an npm: alias:
pnpm add <alias>@npm:<package>
pnpm add <alias>@npm:<package>@<version-or-tag>
The package after npm: may be scoped and versioned. 예시:
pnpm add babel-core@npm:@babel/core@8.0.6
This writes babel-core as the dependency name while resolving
@babel/core@8.0.6 as the target package. The npm: part is the npm
package-alias protocol, not a named registry;
registry routing still follows the target package's default or scope-specific
npm registry configuration.
See Aliases for more examples.
패키지 관리자 또는 런타임 추가#
추가된 버전: v12.0.0-rc.6 (pnpm v12 전용)
Naming a package manager (npm, yarn or bun) records which one the project uses instead of installing the npm package that shares the name:
pnpm add yarn@4
writes "packageManager": "yarn@4.18.0". npm and Bun are recorded as a range in devEngines.packageManager instead. Each write removes the other field. Naming a runtime (node, deno) records it under engines.runtime, as the explicit node@tool:22 spelling does since v12.13.0. bun is both, and is declared as the project's package manager unless you ask for the runtime (pnpm add bun@tool:1.3.0).
전역적으로는 pnpm add -g yarn이 Classic 전용 yarn 패키지가 아닌 현재 Yarn 라인을 설치하고, pnpm add -g node@22는 Node.js를 다운로드하는 래퍼가 아닌 해당 Node.js 릴리스를 설치합니다.
A specifier that locates a package rather than asking for a released version, such as pnpm add yarn@npm:yarn@1.22.22 or pnpm add yarn@yarnpkg/berry, installs what it names, as an ordinary dependency.
Adding the Rust toolchain#
Added in: v12.11.0
rust names the Rust toolchain, not the npm package of that name. The version is a Rust release channel: a version (1.95.0 or 1.95), stable, beta, nightly, or a dated channel such as nightly-2026-01-01. A bare rust asks for stable.
In a project, pnpm add rust@1.95 pins the toolchain in the rust-toolchain.toml that governs the project, the nearest one at or above it in the workspace. It creates one in the project if there is none, and changes only the channel, keeping the rest of the file. With cargo.enabled, the toolchain is installed too. Nothing is added to package.json.
pnpm add -g rust@stable installs the toolchain globally. The cargo, rustc, and other Rust commands run it outside projects whose rust-toolchain.toml names a toolchain of their own. pnpm update -g rust installs the newest release of its channel, pnpm ls -g lists it, and pnpm remove -g rust removes it.
Protocol-prefixed selectors#
A selector may carry the protocol in front of the name rather than after it:
pnpm add jsr:@scope/pkg
pnpm add npm:pkg@^1.0.0
pnpm add workspace:pkg@*
Package URLs#
Added in: v12.5.0
pnpm add accepts Package URLs for npm, Cargo, and Python packages:
pnpm add pkg:npm/express@4.18.2
pnpm add pkg:cargo/serde@1.0.188
pnpm add pkg:pypi/requests@2.31.0
These save dependencies to package.json, Cargo.toml, and pyproject.toml, respectively. Cargo and Python use their ecosystem configuration. pkg is a reserved specifier prefix, regardless of case, and cannot be used as a named registry alias.
옵션#
--save-prod, -P, -p#
지정한 패키지를 일반 dependencies로 설치합니다.
--save-dev, -D, -d#
지정한 패키지를 devDependencies로 설치합니다.
--save-optional, -O, -o#
지정한 패키지를 optionalDependencies로 설치합니다.
--save-exact, -E, -e#
저장된 의존성은 pnpm의 기본 semver 범위 연산자를 사용하지 않고 정확한 버전으로 구성됩니다.
--save-build#
Install crate: packages as Cargo build dependencies.
--save-peer#
--save-peer를 사용하면 하나 이상의 패키지를 peerDependencies에 추가하고 개발 종속성으로 설치합니다. --no-save-peer overrides a savePeer: true setting.
--save-types#
Added in: v12.6.0
Saves available @types/* packages in devDependencies alongside registry
dependencies. Packages that declare bundled TypeScript types are skipped.
pnpm add express --save-types
# saves express to dependencies, @types/express to devDependencies
Set saveTypes: true in pnpm-workspace.yaml to enable this by default. --no-save-types overrides that setting.
--save-prefix <prefix>#
The prefix of the saved version range: ^, ~, = for an explicit exact pin, or an empty string for a bare exact version. Overrides the savePrefix setting.
--tilde#
Added in: v12.6.0
Alias for --save-prefix=~. Saved dependencies will be configured with a tilde
range (~1.2.3) instead of the default caret range (^1.2.3).
--save-catalog#
새 종속성을 기본 catalog에 저장합니다.
--save-catalog-name <catalog_name>#
새 종속성을 지정한 catalog에 저장합니다.
--config#
Save the dependency to configDependencies.
Since v12.12.0, the saved range follows the same rules as for a dependency in package.json.
--ignore-workspace-root-check#
Adding a new dependency to the root workspace package fails, unless you pass
--ignore-workspace-root-check or target the root with -w (--workspace-root).
예: pnpm add debug -w.
--global, -g#
패키지를 전역으로 설치합니다. 자세한 내용은 Global Packages를 참고하세요.
공백으로 구분된 각 패키지는 각각 별도의 격리된 디렉터리에 설치됩니다. 여러 패키지를 하나의 격리된 설치로 묶으려면(종속성을 공유하고 함께 제거되도록) 쉼표로 구분된 목록으로 전달하세요. 예: pnpm add -g eslint,prettier.
--workspace#
워크스페이스에서 발견된 경우에만 새 의존성을 추가합니다. The dependency is
saved with the workspace: protocol
and linked from the workspace project that provides it. When no workspace
project provides the package, the command fails instead of falling back to the
registry.
--allow-build#
설치 중 postinstall 스크립트 실행이 허용된 패키지 이름 목록입니다.
예시:
pnpm --allow-build=esbuild add my-bundler
이렇게 하면 esbuild의 postinstall 스크립트를 실행하고 pnpm-workspace.yaml의 allowBuilds 필드에도 추가합니다. 따라서 앞으로 esbuild는 항상 스크립트 실행이 허용됩니다.
Since v12.4.0, prefixing a name with ! denies the build instead:
pnpm add --allow-build=!core-js my-bundler
writes allowBuilds: { core-js: false }, so the package is never asked about again. Global installs (pnpm add -g) record the denial too.
--lockfile-only#
Update package.json and pnpm-lock.yaml without downloading dependencies or writing node_modules.
--force#
Reinstall every package the lockfile names, relinking packages that an earlier install already linked.
--lockfile-dir <dir>#
The directory in which pnpm-lock.yaml is created. Same as the lockfileDir setting.
--prod, --production#
Leave devDependencies out of node_modules.
--dev#
Leave dependencies out of node_modules.
--[no-]optional#
Include or exclude optionalDependencies from node_modules.
--[no-]auto-dedupe#
Enable or disable the autoDedupe setting for this install.
--ignore-scripts#
Do not run the lifecycle scripts of the project or its dependencies. Same as the ignoreScripts setting.
--ignore-pnpmfile#
Disable the pnpmfile hooks, including the pnpmfiles of config dependencies.
--registry#
Specify the registry to use for this installation:
pnpm add --registry=https://registry.npmjs.org/ lodash
--filter <package_selector>#
--cpu=<name>#
설치할 네이티브 모듈의 CPU 아키텍처를 재정의합니다. 허용되는 값은 process.arch에서 파생된 package.json의 cpu 필드와 동일합니다.
--os=<name>#
설치할 네이티브 모듈의 OS를 재정의합니다. 허용되는 값은 package.json의 os 필드와 동일하며, 이는 process.platform에서 파생됩니다.
--libc=<name>#
설치할 네이티브 모듈의 libc를 재정의합니다. 허용되는 값은 package.json의 libc 필드와 동일합니다.