From 8f705607fe40f37b52e0ba8b57aa618aad228324 Mon Sep 17 00:00:00 2001 From: Manuel Schiller Date: Tue, 30 Dec 2025 14:22:29 +0100 Subject: [PATCH] fix: vite preview waits for child server to be ready before returning --- src/build/vite/preview.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/build/vite/preview.ts b/src/build/vite/preview.ts index 9dd5c4ebc1..fe1cbc9222 100644 --- a/src/build/vite/preview.ts +++ b/src/build/vite/preview.ts @@ -68,7 +68,7 @@ export function nitroPreviewPlugin(ctx: NitroPluginContext): VitePlugin { consola.info(buildInfo.commands?.preview); console.log(""); - const { getRandomPort } = await import("get-port-please"); + const { getRandomPort, waitForPort } = await import("get-port-please"); const randomPort = await getRandomPort(); const child = spawn(command, args, { stdio: "inherit", @@ -116,6 +116,8 @@ export function nitroPreviewPlugin(ctx: NitroPluginContext): VitePlugin { res.end(`Nitro preview server is not running.`); } }); + + await waitForPort(randomPort, { retries: 20, delay: 500 }); }, } satisfies VitePlugin; }