pnx

别名:pnpm dlx、pnpx

从注册源中获取软件包而不将其安装为依赖项,热加载它,并运行它暴露的任何默认命令二进制文件。

例如,若要在任何地方使用 create-vue 来初始化一个 Vue 项目,而不想在另一个项目下安装它,你可以运行:

pnx create-vue my-app

这将从注册源获取 create-vue 并使用给定的参数运行它。

你还可以指定想使用的软件包的确切版本:

pnx create-vue@next my-app

catalog: 协议也被支持, 允许你使用工作区目录中定义的版本:

pnx shx@catalog:

运行包管理器或运行时#

新增于:v12.0.0-rc.6(仅限 pnpm v12)

Naming one of the package managers pnpm provisions (pnpm, npm, yarn, bun), or a runtime (node, deno, bun), provisions the real thing instead of installing the npm package that shares its name:

pnx yarn@4 install
pnx npm@11 ci
pnx bun@1.3.0 install
pnx node@22 --version

The npm packages with those names are either a different line of the tool or a wrapper that downloads it. For example, Yarn 4 is published as @yarnpkg/cli-dist, so pnx yarn@4 runs Yarn 4 itself, and pnx node@22 runs that Node.js release.

如果指定符用于定位软件包,而非请求特定发布版本,则会按原样安装其所指定的包:

pnx yarn@npm:yarn@1.22.22
pnx yarn@yarnpkg/berry

--package 指定一个包管理器,从而选择运行该包管理器的哪条命令:

pnx --package npm@11 npx create-something

Running a Rust release#

Added in: v12.11.1

--package=rust@<channel> runs a tool of that Rust toolchain release, such as cargo or rustc. pnpm installs the release into the store first. The channel is written the way rust-toolchain.toml writes it, and a bare rust means stable.

pnx --package=rust@nightly-2026-01-01 cargo build --target wasm32-unknown-unknown

The release gets the profile, components, and targets of the rust-toolchain.toml that governs the current directory, plus the target of each --target argument.

配置项#

--package <name>#

在运行命令之前要安装的软件包。

示例:

pnx --package=@pnpm/meta-updater meta-updater --help
pnx --package=@pnpm/meta-updater@0 meta-updater --help

可以为安装提供多个软件包:

pnx --package=yo --package=generator-webapp yo webapp --skip-install

--allow-build#

A list of package names that are allowed to run build scripts during installation. Repeat the option or, since v12.23.0, separate names with commas.

示例:

pnx --allow-build=esbuild my-bundler bundle

The actual packages executed by pnx are allowed to run build scripts by default. 因此,如果在上面的例子中 my-bundler 必须在执行之前构建,那么它就会被构建。

Prefixing a name with ! denies its build scripts, including for the executed package itself:

pnx --allow-build=!my-bundler my-bundler bundle

When a dependency's build scripts are skipped, pnx prompts you to approve them in an interactive terminal. This also applies when reusing a cached install that still has builds awaiting approval. Approved scripts run before the requested command.

Approval decisions are saved in the isolated pnx cache. They do not change the calling project's build settings.

Without an interactive terminal, unapproved build scripts remain skipped. Use --allow-build to allow the dependencies whose scripts the command needs.

--shell-mode, -c#

在 shell 中运行该命令。 Uses /bin/sh on UNIX and cmd.exe on Windows.

示例:

pnx --package cowsay --package lolcatjs -c 'echo "hi pnpm" | cowsay | lolcatjs'

--minimum-release-age <minutes>, --minimum-release-age-exclude <package-spec>#

Added in: v12.23.0

Set minimumReleaseAge and minimumReleaseAgeExclude for this run, as they do for pnpm install.

--cpu, --os, --libc#

Choose which platform-tagged optional dependencies the pnx install keeps, by CPU architecture, operating system, and C library (glibc or musl). Repeat an option or separate values with commas:

pnx --cpu arm64,x64 --os linux some-cli

--silent, -s#

只打印执行命令的输出。

安全和信任政策#

pnx (and its pnpm dlx / pnpx aliases) honors the project-level security and trust policy settings when resolving and fetching the requested package:

这意味着 pnx 将拒绝执行新发布的或信任度不足的软件包,就像常规的 pnpm install 一样。

pnx ignores other project-local execution, hook, and directory settings in the current directory (pnpmfile, globalPnpmfile, configDependencies, scriptShell, cacheDir, storeDir, ignoreScripts, overrides, packageExtensions, and patchedDependencies), while keeping user-level global configuration active.