ijavascript icon indicating copy to clipboard operation
ijavascript copied to clipboard

Possible to start kernel with `-r esm`?

Open kylebarron opened this issue 5 years ago • 4 comments

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 avatar Mar 09 '20 02:03 kylebarron

I also tried putting

require('esm')

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

kylebarron avatar Mar 09 '20 02:03 kylebarron

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 avatar Mar 13 '20 22:03 n-riesco

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'

n-riesco avatar Mar 13 '20 23:03 n-riesco

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

kylebarron avatar Jun 02 '20 21:06 kylebarron