ijavascript
ijavascript copied to clipboard
Possible to start kernel with `-r esm`?
Hello! This is a great project!
I searched in the issues and didn't find any mention of this... Is it possible to start node with -r esm? This preloads esm, and should allow using import in the kernel.
I.e. in the terminal I can do:
> cat index.js
const x = "helloworld"
export default x
> node -r esm
> import test from '.';
> test
'helloworld'
I tried to change the kernelspec options a bit, but the kernelspec starts the ijskernel executable, not node. Here's my kernelspec:
{
"resource_dir": "/Users/kyle/Library/Jupyter/kernels/javascript",
"spec": {
"argv": [
"ijskernel",
"--hide-undefined",
"{connection_file}",
"--protocol=5.1"
],
"env": {},
"display_name": "Javascript (Node.js)",
"language": "javascript",
"interrupt_mode": "signal",
"metadata": {}
}
}
I also tried putting
require('esm')
in a file called by --startup-script, but import still didn't work in the jupyter console.
I need to investigate what esm does, but it doesn't seem to work with IJavascript.

I'm still testing, but to answer your original question, you can set the env variable NODE_OPTIONS to pass any flags to node, e.g.:
$ NODE_OPTIONS="-r esm" node
Welcome to Node.js v12.16.1.
Type ".help" for more information.
> import test from './index.js'
undefined
> test
'helloworld'
When I set NODE_OPTIONS="-r esm --experimental-repl-await", Atom won't start. I'm guessing that conflicts with some Electron requirements.