-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: add shell option to npm spawn on Windows #1815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: add shell option to npm spawn on Windows #1815
Conversation
- Fixes EINVAL error when running npm install on Windows - Adds shell: true to spawn options in run_npm_install function - Makes spawn call consistent with other spawn calls in codebase - Resolves GitHub issues HeyPuter#1748 and HeyPuter#1797
|
I almost worked one day to find this, please review as soon as possible and feel free to ask anything... |
|
Hey @veerababu1729. thank you for you PR. I've assigned @ProgrammerIn-wonderland to review this. Please stay tuned. |
|
I think @KernelDeimos mentioned on call that we shouldn't do (shell: true) since it says a deprecation warning in shell but I'll check if that's still the case |
|
yeah this gives me the deprecation warning on startup. Instead of using shell: true, maybe we should stop using npm.cmd on windows? regular npm works fine for me |
|
I suspect Yesterday I wrote a good explanation of the situation but GitHub didn't save the comment I apparently didn't send so we can't have everything; I'll try my best to recreate that: apparently the Node.js maintainers decided that passing args with shell:true should be deprecated which means it might be removed in a future version of node (i.e. instead of getting a warning here, this would be an error and Puter won't be able to continue running). The rationale here makes sense: the fact that spawn accepts this array of input args kind of implies that it will properly process and escape them for you, but it doesn't. (and in hindsight, how could it with In our case the security concern isn't applicable - we're passing a static string. It turns out (and I didn't realize this) that you can just pass the argument in the string in the first parameter. This is only available with Here's my "try everything and see what sticks" solution: const executables = ['npm', 'npm.cmd'];
const spawners = [
(exe) => spawn(exe, 'install', { cwd: path, stdio: "pipe" }),
(exe) => spawn(`${exe} install`, { cwd: path, stdio: "pipe" }),
];
for ( const exe of executables ) {
for ( const spawner of spawners ) {
try {
spawner(exe);
} catch (e) {
// ...
continue;
}
break;
}
}
const proc = spawn(npmCmd + ' install', { shell: true, cwd: path, stdio: "pipe" }); |
|
Let me test your proposal code and let you know....... |
|
any updates |
Description
Fixes Windows-specific EINVAL error when spawning npm install commands.
Problem
On Windows, the run_npm_install function in Kernel.js was failing with
spawn EINVALerror because it was missing theshell: trueoption when spawningnpm.cmd.Solution
shell: trueto spawn options in run_npm_install functionProcessService.jsand LocalTerminalService.js)Changes
shell: trueto spawn optionsFixes
Why Windows Needs shell: true:
Proof from Codebase:
Other spawn calls in the same codebase already use shell: true:
Testing
Type of Change