-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable consuming of ES modules in extensions #130367
Comments
(Experimental duplicate detection) |
Closing after 15 days of no reply. |
cc @jrieken |
Sounds like a duplicate of #116056. Is it possible to reopen that issue? The VS Code extension host currently only accepts CJS module, as shown in the (trimmed) error message below:
However, I think ES module will be more convenient in future. Besides, TypeScript can transpile dynamic |
For what it's worth, I ran into this trying to update |
FYI @TylerLeonhardt one of the Code issues I'd love to see fixed 😃 |
Includes module import workaround for microsoft/vscode#130367 and microsoft/TypeScript#43329 🤯
TypeScript 4.5 will perhaps have a new See |
Excuse me, @TylerLeonhardt, do you know why my comment above was marked as spam? I have to assume that was a mistake. |
@andschwa I'm sorry, it might have been me that marked the comment as spam, but I don't remember doing it. I personally tend to hide comments that do not bring any value to the underlying discussion or distract from it. |
For SEO, here is a similar error message I've received for an LSP extension after packaging and installing VSIX. It appeared in the Output view > Extension Host channel
|
VS Code 1.94 now ships the ESM build in the stable channel: 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. |
Hmm, we should wait |
Latest vscode I use esm work fine 🎉🎉🎉 |
Unfortunately |
Which repositories? This target is cjs |
Agreed, very important to clarify using ESM modules and compiling to CJS is not the same as using them "natively" |
@yxw007, |
@igorskyflyer @CoffeeChaton @JustinGrote |
You need to be very careful what you are saying. You are not "using esm", you are transpiling to commonjs, it's a big difference. |
So can we use untranspiled ESM? |
@NullVoxPopuli not yet, while vscode itself is using ESM now, the extension engine is still bootstrapped via AMD, so extensions still have a commonjs entrypoint and thus need to continue to be commonjs when compiled. |
Maybe someone from vscode can clarify what is the game plan to get ESM support for extensions? |
I am not a vscode team member, but it has to be fixed in the vscode-loader repository is my current understanding, here is the upstream issue for that: microsoft/vscode-loader#56 |
That issue is dated February 29, 2024 and it doesn't seem very active. :-( Is this the only remaining issue to be fixed? |
@axefrog #130367 (comment) |
Compilation is easy. |
VSCode makes sourcemaps really easy to work with so that you pretty much can't tell the difference, you can also use tools like esbuild/register to work with the ts files "directly" (they get transpiled on the fly in node) |
@JustinGrote Thankyou! Works beautifully. For anyone else arriving here, I'm using Bun.build for this. It is shockingly fast. CLI:
Documentation: https://bun.sh/docs/bundler |
There are now instructions in vscode docs for configuring esbuild: This can also be auto configured as one of the options when scaffolding a new extension using yeoman |
When developing extensions and using either JavaScript or TypeScript we are unable to consume ES modules, only somewhat legacy CommonJS modules, setting the
type
tomodule
and rewriting the extension to useimport
instead ofrequire
breaks the extension, generating an exception that states that all modules should useimport
instead ofrequire
in internal VS Code JavaScript files, I conclude it's caused by thetype: module
that forces Node to treat all.js
files as ES modules. Tried using TypeScript which transpiles its own syntax to CommonJS module - so that's a no, I have also tried using just.mjs
extension, again the same issue.What is the status of this issue and are there plans to enable using of ES modules in extension development? That (could) bring somewhat big performance gains when bundling extensions with, for example,
esbuild
because it would enable tree-shaking - dead code removal, thus loading only necessary code. But I think this is not an extension API only issue, right? This needs to be done for VS Code itself?The text was updated successfully, but these errors were encountered: