-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Vite 3.0.0-alpha.12 cannot work in CJS-only environments #8652
Comments
Perhaps we may want to publish a CJS-variant only package of Vite to support this? Or a community maintained version specifically for VSCode 🤔 |
The problem I see with that approach is that a VS Code extension may still transitively depend on the "normal" version of Vite via one of its dependencies, so I'm not sure that can work (that's the case for my extension). |
Does Preview.js bundle a Vite into the extension, or it will use the one from users' local Vite? If it bundles, maybe you could use a bundler to directly transpile the ESM entry for VS Code to consume as CJS? |
I'm not aware of any official plans aside from what's in microsoft/vscode#130367
Preview.js runs an I've tried bundling before (with Vite 2) but ran into a few issues with some dependencies. I will try that again with Vite 3 when I find the time :) Appreciate the help here by the way! I would totally understand if you decide to push forward with the current approach—it really is a VS Code issue at its core. |
Quick update: I tried bundling again with esbuild. Unfortunately it looks like at least some code depends on Vite being an NPM module in its own right, such as vite/packages/vite/src/node/constants.ts Line 54 in 49c0896
|
@fwouts given your comment here https://twitter.com/fwouts/status/1538699965740232704?s=20&t=qIxqqVnJHh_IXhdy5tt5yg, you are not blocked by this issue, no? |
You're right, I wouldn't be blocked entirely. I'd likely choose to stay on V2 as late as possible as this change would be a big refactor that impacts performance of the extension negatively (there would be a fair bit of cross-process communication with this alternative model). I guess that's extra motivation to try fixing VS Code's loader myself 🙂 |
The best would be to fix VS Code's loader, and I imagine the pressure will raise for them during the next months. So maybe we should move forward with the current approach for v3. And we are going to continue to backport important fixes to v2, please flag them if you see something that we should take into account. |
This is affecting us as we use ESM on frontends, CommonJS on backends, and a dev script that spins up vite instances via |
You can create the dev server with commonjs, just that using |
Closing as Preview.js has achieved working with Vite v3 and I think we won't be stepping back to CJS. |
Describe the bug
In environments where ESM isn't supported, such as VS Code (see issue), Vite 3 cannot be loaded.
This is likely because the CJS version of Vite 3 is just a proxy that itself loads ESM modules: #8178. See Anthony's explanation: https://twitter.com/antfu7/status/1538173828492595201.
This will prevent VS Code extensions such as Preview.js from migrating to Vite 3.
Reproduction
https://github.com/fwouts/vite3-vscode-test
System Info
Used Package Manager
yarn
Logs
Validations
The text was updated successfully, but these errors were encountered: