Skip to content

Commit

Permalink
fix: ignore ENOENT in injectSourcesContent
Browse files Browse the repository at this point in the history
This is important for virtual modules and malformed source maps, both of which can throw ENOENT errors when injecting `sourcesContent`.
  • Loading branch information
aleclarson committed Apr 7, 2021
1 parent 0dc6e37 commit 8e9cfe6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/vite/src/node/server/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@ export async function injectSourcesContent(
map: { sources: string[]; sourcesContent?: string[]; sourceRoot?: string },
file: string
) {
const sourceRoot = await fs.realpath(
path.resolve(path.dirname(file), map.sourceRoot || '')
)
try {
var sourceRoot = await fs.realpath(
path.resolve(path.dirname(file), map.sourceRoot || '')
)
} catch (e) {
if (e.code == 'ENOENT') return
throw e
}
map.sourcesContent = []
await Promise.all(
map.sources.map(async (sourcePath, i) => {
map.sourcesContent![i] = await fs.readFile(
path.resolve(sourceRoot, decodeURI(sourcePath)),
'utf-8'
)
try {
map.sourcesContent![i] = await fs.readFile(
path.resolve(sourceRoot, decodeURI(sourcePath)),
'utf-8'
)
} catch (e) {
if (e.code == 'ENOENT') return
throw e
}
})
)
}

0 comments on commit 8e9cfe6

Please sign in to comment.