Skip to content

Commit cb0cbdf

Browse files
authored
fix: Next.JS 12 components testing failing with TypeError: Cannot read property 'traceChild' of undefined (#18648)
1 parent 65458d6 commit cb0cbdf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

npm/react/plugins/next/getRunWebpackSpan.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ import type { Span } from 'next/dist/telemetry/trace/trace'
33
// Starting with v11.1.1, a trace is required.
44
// 'next/dist/telemetry/trace/trace' only exists since v10.0.9
55
// and our peerDeps support back to v8 so try-catch this import
6+
// Starting from 12.0 trace is now located in 'next/dist/trace/trace'
67
export async function getRunWebpackSpan (): Promise<{ runWebpackSpan?: Span }> {
78
let trace: (name: string) => Span
89

910
try {
10-
trace = await import('next/dist/telemetry/trace/trace').then((m) => m.trace)
11+
try {
12+
trace = await import('next/dist/telemetry/trace/trace').then((m) => m.trace)
1113

12-
return { runWebpackSpan: trace('cypress') }
14+
return { runWebpackSpan: trace('cypress') }
15+
} catch (_) {
16+
// @ts-ignore
17+
trace = await import('next/dist/trace/trace').then((m) => m.trace)
18+
19+
return { runWebpackSpan: trace('cypress') }
20+
}
1321
} catch (_) {
1422
return {}
1523
}

0 commit comments

Comments
 (0)