- Published on
Difference Between pnpm create, pnpx, and dlx
- Authors
- Name
- Ripal & Zalak
pnpm create
, pnpx
, and dlx
Difference Between When using pnpm
, you might encounter commands like pnpm create
, pnpx
, and pnpm dlx
. While they may seem similar, they have distinct purposes and use cases. This guide explains their differences, use cases, and best practices.
Overview of the Commands
pnpm exec
:- Searches for a binary locally in
node_modules/.bin
and runs it. - If the binary is not found locally, the command will fail.
- Example:
pnpm exec jest
- Searches for a binary locally in
pnpm dlx
:- Downloads a package remotely from the registry and runs its binary.
- The package is not added as a project dependency.
- Example:
pnpm dlx create-react-app my-app
pnpm create
:- A shorthand for
pnpm dlx create-<first_argument>
. - Specifically designed for creating new apps or projects from templates.
- Example:
pnpm create react-app my-app
- A shorthand for
pnpx
:- Deprecated in favor of
pnpm dlx
. - Behaves like
npx
, running either locally installed binaries or downloading and running them from the registry if not found locally.
- Deprecated in favor of
npx
:- Searches for binaries in
node_modules/.bin
or downloads them remotely if not found. - Example:
npx create-react-app my-app
- Searches for binaries in
Key Differences
Command | Purpose | Behavior |
---|---|---|
pnpm exec | Runs binaries from local node_modules | Fails if the binary is not found locally. |
pnpm dlx | Runs binaries downloaded from the registry | Does not add the package to dependencies . |
pnpm create | Creates new projects | Shorthand for pnpm dlx create-<first_argument> . |
pnpx | Deprecated | Alias for pnpm dlx , combines exec and dlx behaviors. |
npx | Runs local or remote binaries | Automatically downloads if not found locally. |
When to Use Each Command
pnpm exec
for:
Use - Running scripts or tools included in your
package.json
dependencies. - Example: Running
jest
oreslint
installed locally.
pnpm dlx
for:
Use - Executing CLI tools from the npm registry without adding them as dependencies.
- Example: Running a one-off tool like
http-server
.
pnpm create
for:
Use - Initializing new projects or applications using boilerplate templates.
- Example: Bootstrapping a React project with
pnpm create react-app
.
pnpx
:
Avoid - Use
pnpm dlx
instead, aspnpx
is deprecated.
npx
(if not using pnpm
):
Use - Running one-off commands in projects that use
npm
instead ofpnpm
.
Best Practices
- Prefer
pnpm create
for setting up new projects from templates. - Use
pnpm dlx
for running tools directly from the registry without adding dependencies. - Always commit
pnpm-lock.yaml
for reproducible builds.
FAQs
pnpx
deprecated?
Why is pnpx
was replaced by pnpm dlx
to separate the functionality of running local binaries (pnpm exec
) and remote binaries (pnpm dlx
). This separation aligns with pnpm
's philosophy of clarity and explicitness.
pnpm exec
and pnpm dlx
?
What is the difference between pnpm exec
only runs locally installed binaries.pnpm dlx
downloads and runs binaries from the registry without installing them as dependencies.
pnpm create
instead of pnpm dlx
?
When should I use Use pnpm create
when creating new projects, as it automatically maps to templates like create-react-app
or create-svelte
.
Conclusion
Understanding the differences between pnpm create
, pnpx
, and pnpm dlx
is essential for efficient project management and development. By choosing the right command for your task, you can streamline your workflow and maintain clarity in your projects.