Domiii / Domiii/dbux

ESM Support

Open
#562 0 comments 0 reactions 1 assignee Claimed by @Domiii View on GitHub
enhancement future-work
Dominant language
JavaScript
Stars
171
Forks
13
PR merge metrics
No merged PRs in 30d

Description

* [ ] Fix `@dbux/cli`'s [`run` command](https://github.com/Domiii/dbux/blob/master/dbux-cli/src/commands/run.js)
* [x] Add code to import `esm`s
* → more explanations [here](https://github.com/nodejs/node/issues/31710)
* [ ] Automatically determine whether the target is `esm` or `commonjs`, and `require` or `import` correspondingly.
* [ ] Node: Requires `babel-register` to support [ESM hooks](https://nodejs.org/api/esm.html#esm_hooks)
* Possible alternative of addressing the issue of a `package.json` with `"type": "module", where it errors out
* → First `try` `require`, and if it complains about `ESM`, then try as dynamic `import`. Also warn if `esnext` flag is not set.
* However, there might be more issues down the line (need to test)
* Maybe, since we can already convert everything to `commonjs`, we can somehow force node to load it as `commonjs` and then do things the old way?
* NOTE: those hooks are currently in experimental stage, so this might not happen all too soon.
* References
* [Official Docs](https://babeljs.io/docs/en/babel-register#experimental-babel-8-implementation) confirm our suspision:
> @babel/register does not support compiling native Node.js ES modules on the fly, since currently there is no stable API for intercepting ES modules loading.
* [SO: How can I use @babel/register (or alternative) in conjunction with native ESM in Node?](https://stackoverflow.com/questions/67085788/how-can-i-use-babel-register-or-alternative-in-conjunction-with-native-esm-in)
* [ ] Web: TODO(how to hook into web modules getting loaded?)
* [ ] Test with latest version of [node-fetch](https://github.com/node-fetch/node-fetch)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.