obaydmerz / powerjs

Do the powershell magic... right from your script!
MIT License
4 stars 2 forks source link

PowerJS fails to start if pwsh is not installed #7

Open rsmarples opened 6 months ago

rsmarples commented 6 months ago

child_process:spawn does not throw any error directly as it forks a process Instead, errors are emitted and need to be listened to. error is emitted on errors, and spawn on success. https://nodejs.org/api/child_process.html#event-error

As such, only the first element of additionalShellNames is considered.

Workaround for vanilla windows without PowerShell-7:

const psOptions = {
    additionalShellNames: ['powershell'],
    extensions: [],
    dlls: {}
};
const ps = new PowerJS(psOptions);
mdodge-ecgrow commented 5 months ago

I was having issues getting this to run in my Node. I installed Powershell 7 and still got the same errors. Then I tried using the options above and now getting this error: Powershell init has an error!. Any ideas? Is there a debug mode?

If I remove the options object, I get these errors: Error: spawn pwsh ENOENT. Error: Shell took too long to start!.

rsmarples commented 4 months ago

Whilst I have contributed to this project, I felt that the design is unworkable. To fix the issue and the equally important issue of getting a decent error message when things go wrong would have involved breaking the API to much.

I have created simpler more light weight variant PowerShell-Host which is available as a npm.