From b3294cafdcd0522d57ed087516e526bbe29b9178 Mon Sep 17 00:00:00 2001 From: soso Date: Fri, 6 Jan 2023 02:00:38 +0400 Subject: [PATCH] Rebuilds don't happen in watch mode after the first rebuild throws an error during the load function. The position of the watcher changed so that the file review would start before the load function is executed, and in the event of an error, the primary renderer will not crash and the file will be able to be watched. --- packages/vite/src/node/server/transformRequest.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index f10cfde5ac3b87..4499c2cdf753ca 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -170,8 +170,14 @@ async function loadAndTransform( let code: string | null = null let map: SourceDescription['map'] = null + // Ensure that the module is in the graph before it is loaded and the file is checked. + // This prevents errors from occurring during the load process and interrupting the watching process at its inception. + const mod = await moduleGraph.ensureEntryFromUrl(url, ssr) + ensureWatchedFile(watcher, mod.file, root) + // load const loadStart = isDebug ? performance.now() : 0 + const loadResult = await pluginContainer.load(id, { ssr }) if (loadResult == null) { // if this is an html request and there is no load result, skip ahead to @@ -233,9 +239,6 @@ async function loadAndTransform( err.code = isPublicFile ? ERR_LOAD_PUBLIC_URL : ERR_LOAD_URL throw err } - // ensure module in graph after successful load - const mod = await moduleGraph.ensureEntryFromUrl(url, ssr) - ensureWatchedFile(watcher, mod.file, root) // transform const transformStart = isDebug ? performance.now() : 0