Skip to content

Commit

Permalink
fix(sourcemap): tolerate virtual modules in sources array (#5587)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson authored and patak-dev committed Nov 9, 2021
1 parent 93c0016 commit feaf355
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/vite/src/node/server/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const debug = createDebugger('vite:sourcemap', {
onlyWhenFocused: true
})

// Virtual modules should be prefixed with a null byte to avoid a
// false positive "missing source" warning. We also check for certain
// prefixes used for special handling in esbuildDepPlugin.
const virtualSourceRE = /^(\0|dep:|browser-external:)/

interface SourceMapLike {
sources: string[]
sourcesContent?: (string | null)[]
Expand All @@ -30,7 +35,7 @@ export async function injectSourcesContent(
const missingSources: string[] = []
map.sourcesContent = await Promise.all(
map.sources.map((sourcePath) => {
if (sourcePath) {
if (sourcePath && !virtualSourceRE.test(sourcePath)) {
sourcePath = decodeURI(sourcePath)
if (sourceRoot) {
sourcePath = path.resolve(sourceRoot, sourcePath)
Expand Down

0 comments on commit feaf355

Please sign in to comment.