From f8367e88d201221af46033475c4800607e902c74 Mon Sep 17 00:00:00 2001 From: Ishan Gupta <141325549+chocothunder5013@users.noreply.github.com> Date: Sat, 28 Feb 2026 06:32:53 +0530 Subject: [PATCH] fix(dlx): print help message when no arguments are provided (#10690) * fix(dlx): print help message on calling pnpm dlx without arguments Running `pnpm dlx` with no arguments would crash Node.js with a TypeError as it attempted to call `.indexOf()` on an undefined variable. This commit adds a guard clause and displays the help message instead and exits gracefully. Fixes #10633 * refactor: dlx --------- Co-authored-by: Zoltan Kochan --- .changeset/twenty-parks-end.md | 6 ++++++ exec/plugin-commands-script-runners/src/dlx.ts | 5 ++++- pnpm/test/dlx.ts | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changeset/twenty-parks-end.md diff --git a/.changeset/twenty-parks-end.md b/.changeset/twenty-parks-end.md new file mode 100644 index 0000000000..4e66dc93f1 --- /dev/null +++ b/.changeset/twenty-parks-end.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-script-runners": patch +"pnpm": patch +--- + +Print help message on running pnpm dlx without arguments and exit. diff --git a/exec/plugin-commands-script-runners/src/dlx.ts b/exec/plugin-commands-script-runners/src/dlx.ts index d469f319cc..6412e63149 100644 --- a/exec/plugin-commands-script-runners/src/dlx.ts +++ b/exec/plugin-commands-script-runners/src/dlx.ts @@ -87,7 +87,10 @@ export type DlxCommandOptions = { export async function handler ( opts: DlxCommandOptions, [command, ...args]: string[] -): Promise<{ exitCode: number }> { +): Promise<{ exitCode: number, output?: string }> { + if (!command && (!opts.package || opts.package.length === 0)) { + return { exitCode: 1, output: help() } + } const pkgs = opts.package ?? [command] const fullMetadata = ( ( diff --git a/pnpm/test/dlx.ts b/pnpm/test/dlx.ts index 125092d55b..352e2dc523 100644 --- a/pnpm/test/dlx.ts +++ b/pnpm/test/dlx.ts @@ -299,6 +299,17 @@ test('dlx uses the node version specified by --package=node@runtime:', } }) +test('dlx without arguments prints help text and exits with 1', () => { + prepareEmpty() + + const result = execPnpmSync(['dlx']) + + expect(result.status).toBe(1) + + const output = result.stdout.toString() + expect(output).toMatch(/Run a package in a temporary environment\./) +}) + describeOnLinuxOnly('dlx with supportedArchitectures CLI options', () => { type CPU = 'arm64' | 'x64' type LibC = 'glibc' | 'musl'