diff --git a/packages/react-dev-overlay/src/middleware.ts b/packages/react-dev-overlay/src/middleware.ts index 21401e902ed2a..1c93985d8d2ca 100644 --- a/packages/react-dev-overlay/src/middleware.ts +++ b/packages/react-dev-overlay/src/middleware.ts @@ -72,26 +72,30 @@ async function findOriginalSourcePositionAndContent( position: { line: number; column: number | null } ) { const consumer = await new SourceMapConsumer(webpackSource.map()) - const sourcePosition: NullableMappedPosition = consumer.originalPositionFor({ - line: position.line, - column: position.column ?? 0, - }) - - if (!sourcePosition.source) { - return null - } + try { + const sourcePosition: NullableMappedPosition = consumer.originalPositionFor( + { + line: position.line, + column: position.column ?? 0, + } + ) - const sourceContent: string | null = - consumer.sourceContentFor( - sourcePosition.source, - /* returnNullOnMissing */ true - ) ?? null + if (!sourcePosition.source) { + return null + } - consumer.destroy() + const sourceContent: string | null = + consumer.sourceContentFor( + sourcePosition.source, + /* returnNullOnMissing */ true + ) ?? null - return { - sourcePosition, - sourceContent, + return { + sourcePosition, + sourceContent, + } + } finally { + consumer.destroy() } }