Feature request: Import support, through file names and esm or --experimental-modules

It’s crazy that runkit doesn’t support most modern front end javacript, at all.

There are 2 potential solutions,

  1. Allow us to name parts of the notebook as files… then we can import them with esm
  2. A checkbox to enable the --experimental-modules flag
1 Like

Hi @hesygolu,

The reason we don’t support this yet is precisely because it is an experimental feature. In fact, it only showed up in its bare bones form very recently in node and is still very unfinished (and arguably not in an entirely usable state). Had we supported any of the previous, now abandoned, incarnations, we’d have a bunch of notebooks that don’t work or would require strange bridging of old proposed solutions vs. current, theoretically stable (but I wouldn’t be surprised if it changes yet again), solution. In my experience most of the “real world” use of esm has been through transpilers (which don’t necessarily match the semantics of “real” import) and things like the “esm” package from node. We are also not terribly excited in betting on any particular userspace implementation.

We are working on ways to arbitrarily set any node flag, which should alleviate this concern in theory, but the reality is that that node ecosystem isn’t really there on esm yet. Is there a particular package that you are unable to use because it is esm? If so, it could certainly help us in determining the right way to move forward.

Thanks,

Francisco

@tolmasky The npm esm module is a pretty good substitute from what I can see:

const esm = require("esm")(module)
global['window'] = global  // package-specific workaround, not general to all modules
const Color = esm("colorjs.io").default

I recommend adding a code snippet like that to the “import not supported” message as a workaround.

For what it’s worth… here’s what I do… yeah you lose syntax highlighting… but the errors are not half bad and it’s fast and it works with the unique native loader and it’s synthetic modules, and could be easily adapted for the ts-node loader.

https://runkit.com/hesygolu/60ca6ecc0bfbaa001a8fd3fa

Basically,

  • I require a module, any module
  • I read where it is
  • I symlink node_modules to that location
  • I write a michael jackson file
  • I run the michael jackson file

Yes, this still has access to all modules without the need to NPM install