Support 3rd party modules using both ESM and CommonJS #2946
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem we had before with node-fetch migrating to an ESM got me thinking about what it would require to make 3rd party modules ESM. So I made this to test having the node_helper being either CommonJS or ESM.
If naming the file
node_helper.mjs
instead ofnode_helper.js
it should load it as ESM instead.This is just a draft, there are a few things left:
import NodeHelper from "../../js/node_helper.js";
which is annoying<script type="module".../>
, probably a bit harder to have the dual support of .mjs and .js without any configuration...