Skip to content

pi install fails with spawn ... ENOENT on Windows when using fnm #4793

@windedge

Description

@windedge

What happened?

pi install npm:<package> fails with ENOENT on Windows when using fnm-managed Node.js:

Installing npm:pi-rtk-optimizer...
Error: spawn c:\Users\<user>\AppData\Roaming\fnm\aliases\default\npm ENOENT

The same issue affects pi update and any other operation that spawns npm.

Steps to reproduce

  1. Install Node.js via fnm on Windows
  2. Run pi install npm:<any-package>

fnm's global bin directory contains both npm (Unix shell script) and npm.cmd (Windows batch shim). findWindowsCommand in packages/coding-agent/src/utils/child-process.ts checks WINDOWS_COMMAND_EXTENSIONS = ["", ".exe", ".cmd", ".bat"] in order, so the extensionless npm shell script is matched before npm.cmd. Since it has no .cmd/.bat extension, it bypasses the shim-resolution logic and is returned as-is. Spawning a Unix shell script on Windows produces ENOENT.

Expected behavior

pi install should resolve npm.cmd, extract npm-cli.js from it, and invoke it via node.exe — same as when npm.cmd is matched first.

Fix: change the extension search order to prefer .exe, .cmd, .bat over the extensionless variant:

-const WINDOWS_COMMAND_EXTENSIONS = ["", ".exe", ".cmd", ".bat"];
+const WINDOWS_COMMAND_EXTENSIONS = [".exe", ".cmd", ".bat", ""];

Version

0.75.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginprogressIssue is being worked on

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions