Skip to content

Commit 44ad321

Browse files
patak-devGeneralsimus
andauthoredApr 7, 2023
fix: ensure module in graph before transforming (#12774)
Co-authored-by: soso <sosotsertsvadze2@gmail.com>
1 parent 313712d commit 44ad321

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎packages/vite/src/node/server/transformRequest.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ async function loadAndTransform(
172172
let code: string | null = null
173173
let map: SourceDescription['map'] = null
174174

175+
// Ensure that the module is in the graph before it is loaded and the file is checked.
176+
// This prevents errors from occurring during the load process and interrupting the watching process at its inception.
177+
const mod = await moduleGraph.ensureEntryFromUrl(url, ssr)
178+
ensureWatchedFile(watcher, mod.file, root)
179+
175180
// load
176181
const loadStart = debugLoad ? performance.now() : 0
177182
const loadResult = await pluginContainer.load(id, { ssr })
@@ -242,9 +247,6 @@ async function loadAndTransform(
242247
err.code = isPublicFile ? ERR_LOAD_PUBLIC_URL : ERR_LOAD_URL
243248
throw err
244249
}
245-
// ensure module in graph after successful load
246-
const mod = await moduleGraph.ensureEntryFromUrl(url, ssr)
247-
ensureWatchedFile(watcher, mod.file, root)
248250

249251
// transform
250252
const transformStart = debugTransform ? performance.now() : 0

0 commit comments

Comments
 (0)
Please sign in to comment.