Skip to content

Commit

Permalink
fix: next trace error (#18189)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachJW34 committed Sep 24, 2021
1 parent 32b9f93 commit db6f909
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions npm/react/plugins/next/findNextWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const debug = require('debug')('@cypress/react')
const getNextJsBaseWebpackConfig = require('next/dist/build/webpack-config').default
const { findPagesDir } = require('../../dist/next/findPagesDir')
const { getRunWebpackSpan } = require('../../dist/next/getRunWebpackSpan')

async function getNextWebpackConfig (config) {
let loadConfig
Expand All @@ -20,6 +21,7 @@ async function getNextWebpackConfig (config) {
}
}
const nextConfig = await loadConfig('development', config.projectRoot)
const runWebpackSpan = await getRunWebpackSpan()
const nextWebpackConfig = await getNextJsBaseWebpackConfig(
config.projectRoot,
{
Expand All @@ -30,6 +32,7 @@ async function getNextWebpackConfig (config) {
pagesDir: findPagesDir(config.projectRoot),
entrypoints: {},
rewrites: { fallback: [], afterFiles: [], beforeFiles: [] },
...runWebpackSpan,
},
)

Expand Down
16 changes: 16 additions & 0 deletions npm/react/plugins/next/getRunWebpackSpan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Span } from 'next/dist/telemetry/trace/trace'

// Starting with v11.1.1, a trace is required.
// 'next/dist/telemetry/trace/trace' only exists since v10.0.9
// and our peerDeps support back to v8 so try-catch this import
export async function getRunWebpackSpan (): Promise<{ runWebpackSpan?: Span }> {
let trace: (name: string) => Span

try {
trace = await import('next/dist/telemetry/trace/trace').then((m) => m.trace)

return { runWebpackSpan: trace('cypress') }
} catch (_) {
return {}
}
}

0 comments on commit db6f909

Please sign in to comment.