Skip to content

Commit

Permalink
fix: handle error without line and column in loc (#12312)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Mar 7, 2023
1 parent 523d6f7 commit ce18eba
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ export async function createPluginContainer(
err.frame = err.frame || generateCodeFrame(err.id!, err.loc)
}

if (err.loc && ctx instanceof TransformContext) {
if (
ctx instanceof TransformContext &&
typeof err.loc?.line === 'number' &&
typeof err.loc?.column === 'number'
) {
const rawSourceMap = ctx._getCombinedSourcemap()
if (rawSourceMap) {
const traced = new TraceMap(rawSourceMap as any)
Expand Down Expand Up @@ -483,6 +487,15 @@ export async function createPluginContainer(
}
}
}

if (
typeof err.loc?.column !== 'number' &&
typeof err.loc?.line !== 'number' &&
!err.loc?.file
) {
delete err.loc
}

return err
}

Expand Down

0 comments on commit ce18eba

Please sign in to comment.