fix(vite): use manifest entry filename for server entry import (#3595)

## Summary
When `rollupOptions.output.entryFileNames` is customized in vite config
(e.g. `[hash].mjs`), the generated `server.js` was hardcoding
`server-entry.mjs` as the import path, causing the server to fail to
start.

This fix reads the actual entry filename from the Vite manifest and uses
it in the generated `server.js` import, falling back to
`server-entry.mjs` when no custom naming is configured.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Peiyu Cui
2026-03-25 18:47:02 +00:00
committed by GitHub
co-authored by Bartek Iwańczuk Claude Opus 4.6
parent cdc14a0c6e
commit 421e3394a2
3 changed files with 44 additions and 2 deletions
+25
View File
@@ -506,6 +506,31 @@ Deno.test({
sanitizeResources: false,
});
Deno.test({
name: "vite build - custom rollup entryFileNames in server.js",
fn: async () => {
await using res = await buildVite(DEMO_DIR, {
rollupOutput: {
entryFileNames: "[hash].mjs",
chunkFileNames: "[hash].mjs",
},
});
const serverJs = await Deno.readTextFile(
path.join(res.tmp, "_fresh", "server.js"),
);
// When custom entryFileNames is set, server.js should use the actual
// hashed filename from the manifest, not hardcoded "server-entry.mjs"
expect(serverJs).not.toContain("server-entry.mjs");
expect(serverJs).toMatch(
/from "\.\/server\/[a-zA-Z0-9_-]+\.mjs"/,
);
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
name: "vite build - env files",
fn: async () => {
+11 -1
View File
@@ -133,7 +133,14 @@ export async function withDevServer(
export async function buildVite(
fixtureDir: string,
options?: { base?: string },
options?: {
base?: string;
rollupOutput?: {
entryFileNames?: string;
chunkFileNames?: string;
assetFileNames?: string;
};
},
) {
const tmp = await withTmpDir({
dir: path.join(import.meta.dirname!, ".."),
@@ -151,6 +158,9 @@ export async function buildVite(
ssr: {
build: {
outDir: path.join(tmp.dir, "_fresh", "server"),
rollupOptions: options?.rollupOutput
? { output: options.rollupOutput }
: undefined,
},
},
client: {