microsoft / microsoft/vscode-loader

Support dynamic import under NodeJS

Open
#36 4 comments 27 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
179
Forks
62
Avg merge
18h 42m
Merged PRs (30d)
2

Description

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 https://github.com/nodejs/node/issues/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: https://github.com/microsoft/vscode/issues/130367

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing where vm.Script is constructed and how the nodeInstrumenter option affects that path. Review Node's importModuleDynamically API and the linked Node issue before choosing an approach; done means dynamic import works in non-ESM NodeJS contexts without removing nodeInstrumenter support.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.