ijavascript
ijavascript copied to clipboard
Add flag to pass command line options to the node session
At the moment this can be achieved using the env variable NODE_OPTIONS.
See #213 and #210 for motivation.
TODO
- [ ] investigate how Node.js implements
NODE_OPTIONS - [ ] decide how to handle the case when
NODE_OPTIONSbreaks the invocation of node
Can you point me to where I can add a PR for this?
I tried
NODE_OPTIONS="-r esm --experimental-repl-await" jupyter notebook
and await syntax still doesn't work. I'd be happy to make a PR, I just don't understand the code layout at this point.
Hi @kylebarron , the package that invokes node is nel.
This is the line that sets the arguments passed onto node.
I've tested the below change (after installing esm):
Session._args = ["-r", "esm", "--eval", server]; // --eval workaround
and it doesn't work. Please, let me know if you get it work.
Before coding a PR, please, discuss here what you have in mind, as changes to nel will affect other packages.
Same issue with --experimental-repl-await, but if you're interested, I could update ijavascript-await to use zeromq@5 (so that it works with the newer versions of node).
Spent a few minutes on this. I'm guessing it has to do with how node interprets --eval. You need --eval {server_code} to be able to run the jupyter server, but it seems that --eval takes precedence over other options. When I pass NODE_OPTIONS: '-r esm' to the spawn's env, that doesn't get run, nor in the _args array.
I've done further testing and I found what the problem is: esm doesn't work with code run by vm.runInThisContext. I tried this:
$ node -r esm
> import test1 from '.';
> test1
'test'
> vm.runInThisContext("import test2 from '.';")
Uncaught:
Syntax Error: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
>
I've opened an issue with esm (https://github.com/standard-things/esm/issues/886)
Note to myself: I also tried to add sourceFiles.unshift("require('esm')"); before this line. And it didn't work.