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 }) )