Skip to content

Commit 7dd645d

Browse files
authored
fix(gatsby): try to get linenumber from compile error (#30615)
1 parent b3051ae commit 7dd645d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/gatsby/cache-dir/fast-refresh-overlay/components/build-error.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export function BuildError({ error }) {
1414
const decoded = prettifyStack(error)
1515
const [filePath] = decoded
1616
const file = filePath.content.split(`\n`)[0]
17+
const lineMatch = filePath.content.match(/\((\d+)[^)]+\)/)
18+
let line = 1
19+
20+
if (lineMatch) {
21+
line = lineMatch[1]
22+
}
1723

1824
return (
1925
<Overlay>
@@ -22,7 +28,10 @@ export function BuildError({ error }) {
2228
<h1 id="gatsby-overlay-labelledby">Failed to compile</h1>
2329
<span>{file}</span>
2430
</div>
25-
<HeaderOpenClose open={() => openInEditor(file, 1)} dismiss={false} />
31+
<HeaderOpenClose
32+
open={() => openInEditor(file, line)}
33+
dismiss={false}
34+
/>
2635
</Header>
2736
<Body>
2837
<h2>Source</h2>

packages/gatsby/cache-dir/fast-refresh-overlay/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function prettifyStack(errorInformation) {
2323
}
2424

2525
export function openInEditor(file, lineNumber = 1) {
26-
window.fetch(
26+
fetch(
2727
`/__open-stack-frame-in-editor?fileName=` +
2828
window.encodeURIComponent(file) +
2929
`&lineNumber=` +

0 commit comments

Comments
 (0)