From 56ee70264bdb6abc58eb760fa7cb41449b0b4092 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 16 Nov 2023 12:06:03 +0100 Subject: [PATCH] fix(browser): wait until vite finishes prebundling of vitest dependencies (#4518) --- packages/browser/src/client/main.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/browser/src/client/main.ts b/packages/browser/src/client/main.ts index 0780333421f8..94a279c3829c 100644 --- a/packages/browser/src/client/main.ts +++ b/packages/browser/src/client/main.ts @@ -94,8 +94,16 @@ async function reportUnexpectedError(rpc: typeof client.rpc, type: string, error ws.addEventListener('open', async () => { await loadConfig() - const { getSafeTimers } = await importId('vitest/utils') as typeof import('vitest/utils') - const safeRpc = createSafeRpc(client, getSafeTimers) + let safeRpc: typeof client.rpc + try { + // if importing /@id/ failed, we reload the page waiting until Vite prebundles it + const { getSafeTimers } = await importId('vitest/utils') as typeof import('vitest/utils') + safeRpc = createSafeRpc(client, getSafeTimers) + } + catch (err) { + location.reload() + return + } stopErrorHandler() stopRejectionHandler()