-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
[SSR] Vite fails to process CJS npm packages #14158
Comments
I'm pretty sure this was intentional from the start. noExternal needs to be for ESM only, hence we had not added CJS shims in the past when Vite processes them. However, I had also thought if we can at least make CJS transform handling a noop (in dev) but I'm not sure how that looks like. It would kinda work the same as not putting them in noExternal in the first place, but it does signal to bundle it in build. |
The problem is that Vite can't process CJS at all. It has to prebundle them which is the default behavior for the browser. It fails in the browser too if you exclude a CJS dep from For the server, it's off by default. Your example does work with I think a heuristic like "automatically add CJS SSR dependencies to |
After adding According to #8917, Quoting @patak-dev from here:
Is that still on the radar? Such heuristic would be extremely helpful. The CJS/ESM issues are by far the biggest pain vite-plugin-ssr users are having. Fixing A glimpse of how painful it is for the user: Every time the user adds an npm package to |
Does Vite actually need to process them or just run these files? Vite-Node just implements Maybe this can partially help with the issue. |
Describe the bug
In the context of SSR, Vite fails to process CJS npm packages.
The linked reproduction is minimal and shows the issue by adding
react
tossr.noExternal
.Another reproduction showcasing that this issue is a blocker for users: brillout/vite-ssr-preact-mui. In general, it often happens that a CJS package needs to be processed by Vite; this issue is a major blocker.
Reproduction
https://github.com/brillout/vite-ssr-noExternal-cjs
Steps to reproduce
See the reproduction's
README.md
.System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: