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
- Install Node.js via fnm on Windows
- 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
What happened?
pi install npm:<package>fails withENOENTon Windows when using fnm-managed Node.js:The same issue affects
pi updateand any other operation that spawnsnpm.Steps to reproduce
pi install npm:<any-package>fnm's global bin directory contains both
npm(Unix shell script) andnpm.cmd(Windows batch shim).findWindowsCommandinpackages/coding-agent/src/utils/child-process.tschecksWINDOWS_COMMAND_EXTENSIONS = ["", ".exe", ".cmd", ".bat"]in order, so the extensionlessnpmshell script is matched beforenpm.cmd. Since it has no.cmd/.batextension, it bypasses the shim-resolution logic and is returned as-is. Spawning a Unix shell script on Windows producesENOENT.Expected behavior
pi installshould resolvenpm.cmd, extractnpm-cli.jsfrom it, and invoke it vianode.exe— same as whennpm.cmdis matched first.Fix: change the extension search order to prefer
.exe,.cmd,.batover the extensionless variant:Version
0.75.1