question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESM plugin support

See original GitHub issue

Is 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:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pgrzesikcommented, Feb 7, 2022

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 👍

1reaction
medikoocommented, Feb 7, 2022

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 to import (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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found