diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index 65c57423206008..6b1ba9ee6c359c 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -20,7 +20,13 @@ export async function injectSourcesContent( if (!isVirtual) { sourcePath = path.resolve(sourceRoot, sourcePath) } - map.sourcesContent![i] = await fs.readFile(sourcePath, 'utf-8') + try { + map.sourcesContent![i] = await fs.readFile(sourcePath, 'utf-8') + } catch (e) { + throw new Error( + `Sourcemap for "${file}" has a non-existent source: "${sourcePath}"` + ) + } }) ) }