Skip to content

PNPM falsely reports "Command not found" on Windows #11000

@maxpatiiuk

Description

@maxpatiiuk

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

10.32.1

Which area(s) of pnpm are affected? (leave empty if unsure)

CLI

Link to the code that reproduces this issue or a replay of the bug

https://github.com/maxpatiiuk/pnpm-windows-false-not-found/

Reproduction steps

  1. Clone this repository

    git clone https://github.com/maxpatiiuk/pnpm-windows-false-not-found
    cd pnpm-windows-false-not-found
  2. Install dependencies: pnpm install

  3. Reproduce the error:

    Windows (wrong error message):

    > pnpm --filter sub-package exec prettier --check test.js
    Checking formatting...
    [warn] test.js
    [warn] Code style issues found in the above file. Run Prettier with --write to fix.
    C:\Users\mak13180\site\pnpm-windows-false-not-found\sub-package:
     ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Command "prettier" not found
    

    macOS/linux (correct error message):

    > pnpm --filter sub-package exec prettier --check test.js
    Checking formatting...
    [warn] test.js
    [warn] Code style issues found in the above file. Run Prettier with --write to fix.
    /Users/mak13180/s/e/pnpm-windows-false-not-found/sub-package:
     ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Command failed with exit code 1: prettier --check test.js
    
    

Describe the Bug

If pnpm --filter not-current-folder-package exec exited with an error, PNPM falsely claims the command was not found

Expected Behavior

It should print ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Command failed with exit code 1: prettier --check test.js instead, just like on mac/linux

Investigation

I think the bug occurs here:

function isErrorCommandNotFound (command: string, error: CommandError, prependPaths: string[]): boolean {
// Mac/Linux
if (process.platform === 'linux' || process.platform === 'darwin') {
return error.originalMessage === `spawn ${command} ENOENT`
}
// Windows
if (process.platform === 'win32') {
const { value: path } = prependDirsToPath(prependPaths)
return !which.sync(command, {
nothrow: true,
path,
})
}
return false
}

On macOS/linux it checks the command output to determine if command failed due to command being not found.

On Windows it uses which. Is it possible which is invoked from a wrong folder when pnpm was called with --filter?

Alternatively, consider looking for the is not recognized as an internal or external command substring instead. This is the expected output if the command is really not found:

> pnpm --filter sub-package exec prettier --check test.js
'prettier' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\mak13180\site\pnpm-windows-false-not-found\sub-package:
 ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Command "prettier" not found

Which Node.js version are you using?

24.11.1

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions