-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit ES modules from JavaScript backend #511
base: master
Are you sure you want to change the base?
Conversation
Disclaimer: most of this PR was written by Claude 3.5 Sonnet
On Windows, the hack to load a file dynamically without ES modules doesn't work, because there it's a
Instead, we might want to:
val jsScript = s"""
|import { main } from '${mjsFilePath}';
|main();
""".stripMargin |
// NOTE: This is a hack since this file cannot use ES imports & exports | ||
// because it doesn't have the .mjs ending. Sigh. | ||
// Also, we add the 'file://' prefix to satisfy Windows. | ||
val jsScript = s"import('file://${mjsFileName}').then(({main}) => { main(); })" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to revisit this: the path should be relative (see #566).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just try using file:filename
instead 🤔
// NOTE: This is a hack since this file cannot use ES imports & exports | |
// because it doesn't have the .mjs ending. Sigh. | |
// Also, we add the 'file://' prefix to satisfy Windows. | |
val jsScript = s"import('file://${mjsFileName}').then(({main}) => { main(); })" | |
// NOTE: This is a hack since this file cannot use ES imports & exports | |
// because it doesn't have the .mjs ending. Sigh. | |
// Also, we add the 'file:' prefix to satisfy Windows. | |
val jsScript = s"import('file:${mjsFileName}').then(({main}) => { main(); })" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhoh.
(node:8164) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
I'll need to think about this, worstcase we need to dynamically get the current file in JS...
ee9d209
to
58c8510
Compare
Resolves #405
Disclaimer: most of this PR was written by Claude 3.5 Sonnet
TODO
.then
loaderHow to use in the browser