diff --git a/.changeset/small-oranges-give.md b/.changeset/small-oranges-give.md new file mode 100644 index 000000000..c464c0a95 --- /dev/null +++ b/.changeset/small-oranges-give.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +show correct error overlay for compiler errors during hot update diff --git a/packages/vite-plugin-svelte/src/handle-hot-update.ts b/packages/vite-plugin-svelte/src/handle-hot-update.ts index 6f3b90ff2..650378045 100644 --- a/packages/vite-plugin-svelte/src/handle-hot-update.ts +++ b/packages/vite-plugin-svelte/src/handle-hot-update.ts @@ -4,6 +4,7 @@ import { log, logCompilerWarnings } from './utils/log'; import { SvelteRequest } from './utils/id'; import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache'; import { ResolvedOptions } from './utils/options'; +import { toRollupError } from './utils/error'; /** * Vite-specific HMR handling @@ -32,7 +33,7 @@ export async function handleHotUpdate( cache.update(compileData); } catch (e) { cache.setError(svelteRequest, e); - throw e; + throw toRollupError(e, options); } const affectedModules = [...modules]; diff --git a/packages/vite-plugin-svelte/src/index.ts b/packages/vite-plugin-svelte/src/index.ts index eef2004bf..3b0e374e2 100644 --- a/packages/vite-plugin-svelte/src/index.ts +++ b/packages/vite-plugin-svelte/src/index.ts @@ -219,11 +219,7 @@ export function svelte(inlineOptions?: Partial): Plugin[] { } const svelteRequest = requestParser(ctx.file, false, ctx.timestamp); if (svelteRequest) { - try { - return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options); - } catch (e) { - throw toRollupError(e, options); - } + return handleHotUpdate(compileSvelte, ctx, svelteRequest, cache, options); } }, async buildEnd() {