You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Since bar-cjs is cjs, it needs to be ssr external and require is not intercepted by Vite. require('foo-cjs') is executed by NodeJs and resolve.dedupe cannot influence the resolution. To make it similar to browser, optimizeDeps is needed for ssr like following:
Thanks for the explanation. And same question to #19461 (comment) it would be great if we can document the detail that CJS packages in SSR should be marked as external.
And another question about alias/dedupe, somehow these 2 options solve the same problem if people want singleton in a certain package like react or react-dom. But why alias is supported only in global config but not per environment like dedupe? Is there any special reason we keep alias global always?
Just in case we need a quick server-only hack. The per env alias sometimes really helps.
And if people want to dedupe a package to a particular version (like between node_modules/.pnpm/[email protected]/node_modules/react or node_modules/.pnpm/[email protected]/node_modules/react), the current dedupe is not enough and meanwhile I don't know how to do it for SSR via alias since it becomes non-external.
Describe the bug
Some CJS packages won't be deduped in SSR env. Here just provide a minimized reproduction. The actual case happened in a complex project.
Reproduction
https://github.com/Jinjiang/reproductions/tree/try-vite-ssr-20250219
Steps to reproduce
How to reproduce:
Open
http://localhost:3000
in browser.Expected in both browser console and terminal:
Actual in terminal:
System Info
Used Package Manager
pnpm
Logs
Expected in both browser console and terminal:
Actual in terminal:
Validations
The text was updated successfully, but these errors were encountered: