DonJayamanne / typescript-notebook

Run JavaScript and TypeScript in node.js within VS Code notebooks with excellent support for debugging, tensorflowjs visulizations, plotly, danfojs, etc
https://marketplace.visualstudio.com/items?itemName=donjayamanne.typescript-notebook
MIT License
905 stars 40 forks source link

ECMAScript module support? #39

Open jaens opened 2 years ago

jaens commented 2 years ago

Does this support the new-style ES modules? (ie. "type": "module" in package.json etc.)

I have a Node.js TypeScript project that compiles to native ES modules (recently migrated, due to depending on some other libraries that are now only shipped as ES modules), and I can't seem to be able to import any of the project's modules in a notebook (inside that project), whichever way I try.

DonJayamanne commented 2 years ago

Not yet, but will be supporting that soon. Thanks for trying this extension and submitting the feature request (plan is to get it in some time next week).

ilyabo commented 2 years ago

Would be really nice if this worked! E.g. right now importing D3 doesn't seem to be possible:

image

jaens commented 2 years ago

@ilyabo Note that (as a workaround) it should be possible to load ESM from CommonJS using eg.

const d3 = await import('d3');

Reference: https://nodejs.org/api/esm.html#import-expressions

ilyabo commented 2 years ago

I am getting the same error :(

image

jaens commented 2 years ago

@ilyabo Ah, I guess the notebook extension's transpiler is also changing import() function calls into require() internally...

In this case you are currently probably out of luck, and this issue is indeed a blocker for importing any ES modules.