pnpx
Execute Node.js packages
TLDR
Execute the binary from a given npm module
Execute a specific binary from a given npm module, in case the module has multiple binaries
Display help
SYNOPSIS
pnpx [options] <command> [<args...>]
pnpx [options] -p <package> [-p <package>...] <command> [<args...>]
PARAMETERS
-p, --package <package>
Specify packages to install before running the command. Can be used multiple times for multiple packages. The package name can include a version (e.g., react-scripts@latest).
-s, --silent
Don't log any output from pnpm itself. Only the output of the executed command will be shown.
--no-install
If the command or package needs to be installed, pnpx will fail instead of performing the installation. Useful in strict environments.
--shell-mode, -c
Execute the command in a shell. This can be useful if the command involves shell-specific syntax or pipe operations.
--offline
Only use packages that are already present in the local pnpm store. Fails if a package needs to be downloaded.
--prefer-offline
Use packages from the local store if possible, but fall back to downloading if a package is not found locally.
--help
Show help information for the pnpx command.
--version
Output the current version of pnpm (and thus pnpx).
DESCRIPTION
pnpx is the command-line tool bundled with pnpm, designed to execute Node.js package binaries without requiring them to be globally installed or explicitly added to your project's node_modules. It functions as pnpm's counterpart to npm's npx command.
When you run pnpx
This utility is invaluable for running one-off command-line tools, scaffolding new projects (e.g., pnpx create-react-app), or trying out package functionalities without cluttering your global environment or project dependencies.
CAVEATS
pnpx requires pnpm to be installed on your system. While it aims for efficiency, initial execution of a new command might involve downloading the package, which requires an internet connection. Be cautious when executing commands from untrusted sources, as pnpx will run them with your user's permissions.
HOW IT WORKS
pnpx first checks if the executable is in your project's node_modules/.bin. If not, it uses pnpm's store to either retrieve a cached version or download and install the package. It then creates temporary symlinks to make the command available in the current shell's PATH for execution. This ensures that the command runs using the specific package version intended, without polluting your global environment.
SCAFFOLDING TOOLS
A common use case for pnpx is to run project scaffolding tools. For example, to create a new React app, you can use pnpx create-react-app my-app. This downloads and executes the create-react-app tool directly without needing to install it globally or adding it as a project dependency first, making it a convenient way to bootstrap new projects.
HISTORY
pnpm, short for 'Performant Node Package Manager,' emerged as a fast and disk-space efficient alternative to npm and yarn. As npm's npx gained popularity for simplifying the execution of Node.js package binaries, pnpm introduced pnpx as its direct counterpart. pnpx leverages pnpm's unique content-addressable store, which uses hard links and symlinks to share dependencies across projects, allowing for highly efficient caching and minimal disk space usage when executing transient commands.