From ed09cb765019a9052b444ea036dc17027133b8eb Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Tue, 20 Jul 2021 20:51:37 -0400 Subject: [PATCH] fix(sourcemap): ensure `sources` and `sourcesContent` are the same length --- packages/vite/src/node/server/sourcemap.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index abfbc5c82ec45e..515b5a605a3157 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -29,15 +29,18 @@ export async function injectSourcesContent( const missingSources: string[] = [] map.sourcesContent = await Promise.all( - map.sources.filter(Boolean).map((sourcePath) => { - sourcePath = decodeURI(sourcePath) - if (sourceRoot) { - sourcePath = path.resolve(sourceRoot, sourcePath) + map.sources.map((sourcePath) => { + if (sourcePath) { + sourcePath = decodeURI(sourcePath) + if (sourceRoot) { + sourcePath = path.resolve(sourceRoot, sourcePath) + } + return fs.readFile(sourcePath, 'utf-8').catch(() => { + missingSources.push(sourcePath) + return null + }) } - return fs.readFile(sourcePath, 'utf-8').catch(() => { - missingSources.push(sourcePath) - return null - }) + return null }) )