Skip to content

Commit

Permalink
fix: ensure module in graph before transforming (#12774)
Browse files Browse the repository at this point in the history
Co-authored-by: soso <sosotsertsvadze2@gmail.com>
  • Loading branch information
patak-dev and Generalsimus committed Apr 7, 2023
1 parent 313712d commit 44ad321
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vite/src/node/server/transformRequest.ts
Expand Up @@ -172,6 +172,11 @@ 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 = debugLoad ? performance.now() : 0
const loadResult = await pluginContainer.load(id, { ssr })
Expand Down Expand Up @@ -242,9 +247,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 = debugTransform ? performance.now() : 0
Expand Down

0 comments on commit 44ad321

Please sign in to comment.