From 370e20dc75ac6980cb8b372fd1b57ab91c3b87b2 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Tue, 20 Jul 2021 21:57:36 +0800 Subject: [PATCH 1/2] fix: handle non-existing files in sourcemap If a source map contains a file in `source` section without uploading the referenced file, Vite will complain about ENOENT. This fix makes Vite more lenient with npm ecosystem's misdemeanor. --- packages/vite/src/node/server/sourcemap.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index 5e11f8491443e4..cdbf96f91352c9 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -14,7 +14,7 @@ export async function injectSourcesContent( map.sourcesContent![i] = await fs.readFile( path.resolve(sourceRoot, decodeURI(sourcePath)), 'utf-8' - ) + ).catch(() => '') }) ) } From 9ffb73e4d40df27d9f32634552041097899d62bd Mon Sep 17 00:00:00 2001 From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Tue, 20 Jul 2021 22:10:32 +0800 Subject: [PATCH 2/2] fix: add more context to the emitted source map Instead of emitting error, forging a source file with a comment as hint. --- packages/vite/src/node/server/sourcemap.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index cdbf96f91352c9..2f516c5985b9b0 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -14,7 +14,7 @@ export async function injectSourcesContent( map.sourcesContent![i] = await fs.readFile( path.resolve(sourceRoot, decodeURI(sourcePath)), 'utf-8' - ).catch(() => '') + ).catch(() => '/* Vite fails to read source because it is missing or a virtual module.*/') }) ) }