n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.18k stars 187 forks source link

Possible to start kernel with `-r esm`? #213

Open kylebarron opened 4 years ago

kylebarron commented 4 years ago

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": {}
  }
}
kylebarron commented 4 years ago

I also tried putting

require('esm')

in a file called by --startup-script, but import still didn't work in the jupyter console.

n-riesco commented 4 years ago

I need to investigate what esm does, but it doesn't seem to work with IJavascript.

Screenshot from 2020-03-13 22-55-03

n-riesco commented 4 years ago

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'
kylebarron commented 4 years ago

When I set NODE_OPTIONS="-r esm --experimental-repl-await", Atom won't start. I'm guessing that conflicts with some Electron requirements.