From ce18eba39f8243a1652dcae4d157540815f105ab Mon Sep 17 00:00:00 2001 From: Wei Date: Tue, 7 Mar 2023 19:58:14 +0800 Subject: [PATCH] fix: handle error without line and column in loc (#12312) --- packages/vite/src/node/server/pluginContainer.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 2aa340234c9788..bb28767f414b0b 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -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) @@ -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 }