Skip to content
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

🤦VS Code extensions do not support esm #114

Open
Adam-it opened this issue Oct 17, 2023 · 11 comments
Open

🤦VS Code extensions do not support esm #114

Adam-it opened this issue Oct 17, 2023 · 11 comments
Labels
⭐ enhancement New feature or request 🤚 on hold I need to wait for something else 🤔 research needs researching before I start hacking
Milestone

Comments

@Adam-it
Copy link
Contributor

Adam-it commented Oct 17, 2023

🎯 Aim

The aim of this issue is to track the support of es modules in VS Code extensions.
Issues with more info:

Currently using CLI for Microsoft 365 directly from PnP builds is not possible due to that, so for now as a temporary workaround the CLI dependency is added from a local version of the package which was reverted to common js
https://github.com/Adam-it/cli-microsoft365/tree/cli-cjs

@Adam-it Adam-it added ⭐ enhancement New feature or request 🤚 on hold I need to wait for something else 🤔 research needs researching before I start hacking labels Oct 17, 2023
@Malix-Labs
Copy link

Yep, that's a serious disappointment.
Did you try using vite?

@Adam-it
Copy link
Contributor Author

Adam-it commented Nov 21, 2023

Yep, that's a serious disappointment.
Did you try using vite?

Not sure how would that help for a dependency that is not used in webview but in the extension itself 🤔. Do you have any example I could check 👍?

@Malix-Labs
Copy link

Malix-Labs commented Nov 22, 2023

Not sure how would that help for a dependency that is not used in webview but in the extension itself 🤔. Do you have any example I could check 👍?

Yep, I use vite to bundle my VSCode extension
It's WIP, but the bundling part works; it bundles from my typescript source written in ESNext to a CJS build
Here is the source code: https://github.com/Malix-off/VSC-Extension-StashFlow/tree/dev

@Adam-it
Copy link
Contributor Author

Adam-it commented Nov 22, 2023

Awesome. I need to check it for sure 🤩. Will it work also if one of the dependencies I use is already build in esm? As this is actually the problem I'm having

@Malix-Labs
Copy link

Will it work also if one of the dependencies I use is already build in esm?
As this is actually the problem I'm having

Yes, it's the main point of bundler, fixing the dumbass cjs vs esm fight and optimize code output with minification and circular resolution, and library imports with tree-shaking
There is theoretically no reason vite couldn't fix your problem in one way or another, I believe

@Adam-it
Copy link
Contributor Author

Adam-it commented Nov 22, 2023

this is awesome. I need to do a deep dive on this in the coming weekend.
Thanks @Malix-off for sharing. You Rock 🤩

@Malix-Labs
Copy link

Malix-Labs commented Nov 23, 2023

You're welcome ❤️

@estruyf
Copy link
Member

estruyf commented Nov 24, 2023

@Malix-off, it is a great tip, also started using Vite a while ago, but now stepping away from it again as Vite dropped CJS support in v5 and will be completely removed in v6.

More information: https://vitejs.dev/guide/migration.html#deprecate-cjs-node-api

I stumbled on this issue as I had some issues with types that were incorrectly referenced during the build and made the extension fail.

It would be better to look at esbuild or tsup to be future-proof.

@Malix-Labs
Copy link

Malix-Labs commented Nov 24, 2023

Vite dropped CJS support in v5

Nope, they dropped their own CJS Node API, which is a good thing imho because it would be kind of a non-sense to use a bundler in a non-ESM environment anyway (actually I'm a bit surprised they released a CJS Node API in the first place)

It means that to use Vite, you would need to use their ESM API (thus, to develop in ESM rather than CJS (I personally very much recommend that no matter what)), but vite will still be available to output CJS

See https://github.com/Malix-off/VSC-Extension-StashFlow/blob/master/vite.config.ts as an exemple

Edit

  1. Okay, I see what you meant because when I tested configs, I stumbled upon the deprecation message.
    That's a false positive because vite takes "module": "cjs" (required for vscode extensions) of package.json as "developing in cjs" rather than "outputing cjs".
    To make it clear that we aren't using cjs, you just have to use the .mjs/.mts extension (docs)
    Oh and btw, thanks for that article, I noticed during my research that you were also the author of it lol

@Malix-Labs
Copy link

Malix-Labs commented Nov 24, 2023

@estruyf @Adam-it ⬆️

@Adam-it
Copy link
Contributor Author

Adam-it commented Jun 6, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement New feature or request 🤚 on hold I need to wait for something else 🤔 research needs researching before I start hacking
Projects
None yet
Development

No branches or pull requests

3 participants