Skip to content

Support dynamic import under NodeJS #36

Open

Description

@Silic0nS0ldier

In a non-ESM context normally import() can be used to bring in ESM code. Under this loader this will be true for browsers, but not NodeJS which does not include an implementation by default for scripts constructed with vm.Script.

Downstream this complicates extension development in VSCode as it means ESM packages can only be used if first transformed into a compatible syntax (usually by a bundler). Note that the extension development host appears to load extensions without using this loader, so such dynamic import restrictions will not be seen there.

At present, I can see 2 paths towards supporting dynamic import.

  1. Supply a callback via the importModuleDynamically option (this API and those which may be needed for the implementation are marked experimental, it may be worth waiting on Roadmap for stabilization of vm modules nodejs/node#37648)
  2. Forfeit the nodeInstrumenter option so the implementation can be simplified to just require (by far easiest and not blocked by experimental API, but will be a breaking change)
    EDIT 2023-03-13: On closer inspection, it appears I read the codepath wrong. This is not an option.

Downstream issue: microsoft/vscode#130367

Activity

  1. metawrap-dev commented on Mar 29, 2024

    @metawrap-dev

    Hoping that this will be available soon so that we can start consuming ESM code in extensions?

  2. v4lentin1879 commented on May 26, 2024

    @v4lentin1879

    Any updates on this one? Is there any way to import ESM code in vscode extensions?

  3. added a commit that references this issue on May 27, 2024
  4. TomasHubelbauer commented on Oct 4, 2024

    @TomasHubelbauer

    VS Code 1.94 now ships the ESM build in the stable channel:
    https://code.visualstudio.com/updates/v1_94#_esm-is-shipping-for-vs-code

    I tested using ESM in extensiom code and that still appears to be unsupported, but hopefully VS Code now shipping ESM means this limitation will be lifted, soon.

  5. jogibear9988 commented on Jan 13, 2025

    @jogibear9988

    I today also tried to use a ESM module in a simple extension, but ended up copying the esm code into the extension (cause it did not work)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions