You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, in reality, not only can I not call it normally after loading the module, but I also cannot use Node.js normally.
Before loading the module, Node.js runs well in my shell:
Loading the module and trying to run a simple script results in an error:
Subsequently, both the Node.js command and the JS code running function of the esh cannot be used normally:
The text was updated successfully, but these errors were encountered:
I looked into this a little bit. Here is the inner exception message for the "exception thrown from JS thread":
There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: [Microsoft.JavaScri…t("console.log(1)")
I made a small PR that will make that inner exception message easier to see for situations like this: #378
Now the actual problem is that PowerShell expects to run scripts on a certain thread (with an associated "runspace") but JavaScript also must run on a particular thread. The Action delegate passed to the Run method gets invoked on the JS thread, but since that delegate is actually a PS script it cannot be executed on that thread.
Currently the NodejsEnvironment class always creates a dedicated thread for each JS environment, so that doesn't allow PS and JS scripts to run on the same thread. However @vmoroz is working on some changes to the libnode embedding API that will give us more flexibility to execute JS on a specific (existing) thread, which I think can work better for interaction with PowerShell.
Another workaround could be to add a NodejsEnvironment.RunScript() and/or RunScriptAsync() method which would run the given script on the JS thread without needing a callback.
I tried to create a PowerShell module to run JS in PowerShell.
However, in reality, not only can I not call it normally after loading the module, but I also cannot use Node.js normally.
Before loading the module, Node.js runs well in my shell:
Loading the module and trying to run a simple script results in an error:
Subsequently, both the Node.js command and the JS code running function of the esh cannot be used normally:
The text was updated successfully, but these errors were encountered: