typescript-notebook icon indicating copy to clipboard operation
typescript-notebook copied to clipboard

ECMAScript module support?

Open jaens opened this issue 2 years ago • 5 comments

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.

jaens avatar Oct 06 '21 11:10 jaens

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).

DonJayamanne avatar Oct 13 '21 06:10 DonJayamanne

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

image

ilyabo avatar Nov 04 '21 13:11 ilyabo

@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

jaens avatar Nov 04 '21 13:11 jaens

I am getting the same error :(

image

ilyabo avatar Nov 04 '21 15:11 ilyabo

@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.

jaens avatar Nov 04 '21 18:11 jaens