Skip to content

Commit 74f2198

Browse files
fix(vite): wait on preview child port to be ready (#3908)
1 parent eecf725 commit 74f2198

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/build/vite/preview.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function nitroPreviewPlugin(ctx: NitroPluginContext): VitePlugin {
6868
consola.info(buildInfo.commands?.preview);
6969
console.log("");
7070

71-
const { getRandomPort } = await import("get-port-please");
71+
const { getRandomPort, waitForPort } = await import("get-port-please");
7272
const randomPort = await getRandomPort();
7373
const child = spawn(command, args, {
7474
stdio: "inherit",
@@ -116,6 +116,8 @@ export function nitroPreviewPlugin(ctx: NitroPluginContext): VitePlugin {
116116
res.end(`Nitro preview server is not running.`);
117117
}
118118
});
119+
120+
await waitForPort(randomPort, { retries: 20, delay: 500 });
119121
},
120122
} satisfies VitePlugin;
121123
}

0 commit comments

Comments
 (0)