standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 147 forks source link

Load ES module from VS Code extension #915

Open hakonhagland opened 2 years ago

hakonhagland commented 2 years ago

I am trying to load an ES module from a VS Code extension, see this question on stackoverflow. I believe I have run into this issue.

In another issue someone suggested to use the esm package. I tried it, see the esm branch, but I still get the following error:

[2022-04-21 15:27:47.180] [exthost] [error] Activating extension undefined_publisher.vscode-test-getport failed due to an error:
[2022-04-21 15:27:47.180] [exthost] [error] /home/hakon/test/vscode/vscode-test-getport/out/main.js:1
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/hakon/test/vscode/vscode-test-getport/node_modules/get-port/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/hakon/test/vscode/vscode-test-getport/out/main.js:4:20)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/home/hakon/test/vscode/vscode-test-getport/out/extension.js:4:18)
    at Function.<anonymous> (node:electron/js2c/asar_bundle:5:13331)

Any suggestions?

See also: https://stackoverflow.com/questions/70620025/how-do-i-import-an-es6-javascript-module-in-my-vs-code-extension-written-in-type

Leedehai commented 2 years ago

According to https://github.com/electron/electron/issues/21457#issuecomment-1099904505 from an Electron maintainer, it seems it is technically unfeasible to support ESM in Electron directly.