fix: execute pnpm with shell on Windows - #18
Conversation
Fixes ENOENT and EINVAL errors when running pnpm via child_process execFileSync on Windows by ensuring it runs with shell: true. Co-authored-by: Gemini <gemini@google.com>
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
I have read the CLA Document and I hereby sign the CLA |
|
I hit the same bug independently and filed #19 before spotting this PR — sorry for the duplicate
That is reachable from the https://github.com/cloudflare/cloudflare-os/blob/aedcda8/run-dev-server.js#L297-L303 So on a checkout under, say, An alternative that avoids the quoting question entirely: export function pnpmCommand(args) {
const execPath = process.env.npm_execpath ?? "";
return process.platform === "win32" && /[\\/]pnpm\.[cm]?js$/i.test(execPath)
? [process.execPath, [execPath, ...args]]
: ["pnpm", args];
}used as The regex test is worth keeping: under I verified the end-to-end result on Windows 11 / Node 22 — Happy for this PR to be the one that lands — just flagging the argument-splitting so it does not |
Thanks for the heads up. To be honest, this is my first public PR, and you spotted an flaw I'm not sure how to handle properly right now. Feel free to push your fix directly to this PR branch or suggest on the diff if you'd like. That would help me learn and get this working for everyone. |
|
Hmm, I was considering merging this PR as falling under the "small, trivially-verified" rule from our contributing policy. However, from the discussion, it sounds like it's actually more subtle. Nothing is trivial it seems. :( So this also looks like something we're going to want to throw our own agents at to try to solve. The issue report #19 looks like it covers the details, so let's move the discussion there? |
Fixes ENOENT and EINVAL errors when running pnpm via child_process execFileSync on Windows by ensuring it runs with shell: true.
This fixes an issue where running
pnpm run-localfails immediately on Windows withENOENTorEINVALerrors coming fromchild_process.execFileSync.Why it was broken
On Windows,
pnpmis installed as a batch script (pnpm.cmd). Node.js'sexecFileSynccannot execute.cmdfiles natively without invoking a shell (likecmd.exe).The fix
I updated the 5 instances of
execFileSync("pnpm", ...)across the codebase to include{ shell: process.platform === "win32" }.