ESM plugin support
See original GitHub issueIs there an existing issue for this?
- I have searched existing issues, it hasn’t been reported yet
Use case description
ESM plugin support allows use of pure ESM package for plugin development.
for example:
export default class MyPlugin {
constructor() {
// ...
}
}
Proposed solution (optional)
Dynamic import can be used for that purpose.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
What does it take to support Node.js ESM? – The Guild
To add support ESM for Node.js, you have two alternatives: ... "cjs" and "esm" without using build-time tools like @rollup/plugin-replace or ...
Read more >babel-esm-plugin - npm
Add this plugin to generate mirrored esm modules for your existing bundles. Latest version: 0.9.0, last published: 3 years ago.
Read more >Esm / es modules / "type": "module" in build plugins? - Support
Hello! I'm writing a build plugin. May I use "type": "module" in package json and then do export async function onSuccess({ netlifyConfig, ...
Read more >babel/plugin-transform-modules-commonjs
This plugin transforms ECMAScript modules to CommonJS. ... When using exports with babel a non-enumerable __esModule property is exported.
Read more >babel-plugin-cjs-esm-interop | API - Packemon
babel-plugin-cjs-esm-interop ... Add the plugin to your root babel.config. ... If you want to support ESM code, you'll need to move away from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot for additional clarification @frozenbonito - I didn’t notice that it was accepted later as a nonexperimental feature 👍
I like the suggestion that @medikoo proposed and if we can ensure such fallback without causing any issues for users that do not use ESM-based plugins then that would be perfect 👍
Node v12 started to be LTS with v12.13.0, and this is the base we aim to support. Nonetheless, I think this can be supported via a progressive enhancement like approach
In v12 which supports ESM, when we attempt to require ESM module, we get an error with
ERR_REQUIRE_ESM
code. Having that we may fallback toimport
(which is safe to be used in a controlled way in all v12 versions), and that way via recovery logic we can provide support to ESM plugins.I think it’s not that difficult to add. It’ll require reconfiguring one internal function to async (which feels safe at quick glance).
One quirk will be, that processing given service will work differently with v12.13.0, where we cannot load ESM at all, and in latest v12, but I think that’s fine