@@ -50,11 +50,95 @@ function getNextJsPackages (devServerConfig: WebpackDevServerConfig) {
50
50
return packages
51
51
}
52
52
53
+ /**
54
+ * Types for `getNextJsBaseWebpackConfig` based on version:
55
+ * - v11.1.4
56
+ [
57
+ dir: string,
58
+ options: {
59
+ buildId: string
60
+ config: NextConfigComplete
61
+ dev?: boolean
62
+ isServer?: boolean
63
+ pagesDir: string
64
+ target?: string
65
+ reactProductionProfiling?: boolean
66
+ entrypoints: WebpackEntrypoints
67
+ rewrites: CustomRoutes['rewrites']
68
+ isDevFallback?: boolean
69
+ runWebpackSpan: Span
70
+ }
71
+ ]
72
+
73
+ * - v12.0.0 = Same as v11.1.4
74
+
75
+ * - v12.1.6
76
+ [
77
+ dir: string,
78
+ options: {
79
+ buildId: string
80
+ config: NextConfigComplete
81
+ compilerType: 'client' | 'server' | 'edge-server'
82
+ dev?: boolean
83
+ entrypoints: webpack5.EntryObject
84
+ hasReactRoot: boolean
85
+ isDevFallback?: boolean
86
+ pagesDir: string
87
+ reactProductionProfiling?: boolean
88
+ rewrites: CustomRoutes['rewrites']
89
+ runWebpackSpan: Span
90
+ target?: string
91
+ }
92
+ ]
93
+
94
+ * - v13.0.0
95
+ [
96
+ dir: string,
97
+ options: {
98
+ buildId: string
99
+ config: NextConfigComplete
100
+ compilerType: CompilerNameValues
101
+ dev?: boolean
102
+ entrypoints: webpack.EntryObject
103
+ hasReactRoot: boolean
104
+ isDevFallback?: boolean
105
+ pagesDir?: string
106
+ reactProductionProfiling?: boolean
107
+ rewrites: CustomRoutes['rewrites']
108
+ runWebpackSpan: Span
109
+ target?: string
110
+ appDir?: string
111
+ middlewareMatchers?: MiddlewareMatcher[]
112
+ }
113
+ ]
114
+
115
+ * - v13.0.1
116
+ [
117
+ dir: string,
118
+ options: {
119
+ buildId: string
120
+ config: NextConfigComplete
121
+ compilerType: CompilerNameValues
122
+ dev?: boolean
123
+ entrypoints: webpack.EntryObject
124
+ isDevFallback?: boolean
125
+ pagesDir?: string
126
+ reactProductionProfiling?: boolean
127
+ rewrites: CustomRoutes['rewrites']
128
+ runWebpackSpan: Span
129
+ target?: string
130
+ appDir?: string
131
+ middlewareMatchers?: MiddlewareMatcher[]
132
+ }
133
+ ]
134
+ */
53
135
async function loadWebpackConfig ( devServerConfig : WebpackDevServerConfig ) : Promise < Configuration > {
54
136
const { loadConfig, getNextJsBaseWebpackConfig } = getNextJsPackages ( devServerConfig )
55
137
56
138
const nextConfig = await loadConfig ( 'development' , devServerConfig . cypressConfig . projectRoot )
57
139
const runWebpackSpan = getRunWebpackSpan ( devServerConfig )
140
+ const reactVersion = getReactVersion ( devServerConfig . cypressConfig . projectRoot )
141
+
58
142
const webpackConfig = await getNextJsBaseWebpackConfig (
59
143
devServerConfig . cypressConfig . projectRoot ,
60
144
{
@@ -69,6 +153,8 @@ async function loadWebpackConfig (devServerConfig: WebpackDevServerConfig): Prom
69
153
isServer : false ,
70
154
// Client webpack config for Next.js > 12.1.5
71
155
compilerType : 'client' ,
156
+ // Required for Next.js > 13
157
+ hasReactRoot : reactVersion === 18 ,
72
158
} ,
73
159
)
74
160
@@ -300,3 +386,14 @@ function changeNextCachePath (webpackConfig: Configuration) {
300
386
debug ( 'Changing Next cache path from %s to %s' , cacheDirectory , webpackConfig . cache . cacheDirectory )
301
387
}
302
388
}
389
+
390
+ function getReactVersion ( projectRoot : string ) : number | undefined {
391
+ try {
392
+ const reactPackageJsonPath = require . resolve ( 'react/package.json' , { paths : [ projectRoot ] } )
393
+ const { version } = require ( reactPackageJsonPath )
394
+
395
+ return Number ( version . split ( '.' ) [ 0 ] )
396
+ } catch ( e ) {
397
+ debug ( 'Failed to source react with error: ' , e )
398
+ }
399
+ }
0 commit comments