-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Which project does this relate to?
Start
Describe the bug
If a package has following package.json and no exports is defined:
{
"name": "my-lib",
"main": "src/index.cjs",
"module": "src/index.mjs"
}Then if it was externalized in vite.config.ts:
// vite.config.ts
const config = defineConfig({
ssr: {
external: true,
},
// rest...
});Then when launch the dev server with vite, the SSR resolution will pick the CJS version of my-lib from main field, although we are importing it.
Your Example Website or App
https://github.com/guyutongxue/vite-ssr-cjs-issue
Steps to Reproduce the Bug or Issue
bun iandcd packages/my-appandbun dev- Launch the App, and you will see the
my-libwas imported as CJS and hydrated later to ESM.
The
my-libjust export a simple function returning which module type it is; and the app code justimportit and render the return value to<App>.
Expected behavior
Expected always ESM with no hydration mistmatch.
Screenshots or Videos
Platform
- Router / Start Version: 1.141.5
- OS: Windows, also reproduced on Mac
- Browser: Edge
- Browser Version: 143.0.3650.80
- Bundler: Vite
- Bundler Version: 7.3.0
Additional context
I'm not sure whether this is a Vite bug because I cannot make a reproducible example code on pure Vite SSR (too low level sorry).
I figured out that TanStack Start run into the code in Vite here:
that won't consider ESM module at all.
coderabbitai
Metadata
Metadata
Assignees
Labels
No labels
