Skip to content

Commit db6f909

Browse files
authored
fix: next trace error (#18189)
1 parent 32b9f93 commit db6f909

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

npm/react/plugins/next/findNextWebpackConfig.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const debug = require('debug')('@cypress/react')
44
const getNextJsBaseWebpackConfig = require('next/dist/build/webpack-config').default
55
const { findPagesDir } = require('../../dist/next/findPagesDir')
6+
const { getRunWebpackSpan } = require('../../dist/next/getRunWebpackSpan')
67

78
async function getNextWebpackConfig (config) {
89
let loadConfig
@@ -20,6 +21,7 @@ async function getNextWebpackConfig (config) {
2021
}
2122
}
2223
const nextConfig = await loadConfig('development', config.projectRoot)
24+
const runWebpackSpan = await getRunWebpackSpan()
2325
const nextWebpackConfig = await getNextJsBaseWebpackConfig(
2426
config.projectRoot,
2527
{
@@ -30,6 +32,7 @@ async function getNextWebpackConfig (config) {
3032
pagesDir: findPagesDir(config.projectRoot),
3133
entrypoints: {},
3234
rewrites: { fallback: [], afterFiles: [], beforeFiles: [] },
35+
...runWebpackSpan,
3336
},
3437
)
3538

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Span } from 'next/dist/telemetry/trace/trace'
2+
3+
// Starting with v11.1.1, a trace is required.
4+
// 'next/dist/telemetry/trace/trace' only exists since v10.0.9
5+
// and our peerDeps support back to v8 so try-catch this import
6+
export async function getRunWebpackSpan (): Promise<{ runWebpackSpan?: Span }> {
7+
let trace: (name: string) => Span
8+
9+
try {
10+
trace = await import('next/dist/telemetry/trace/trace').then((m) => m.trace)
11+
12+
return { runWebpackSpan: trace('cypress') }
13+
} catch (_) {
14+
return {}
15+
}
16+
}

0 commit comments

Comments
 (0)