Skip to content

Commit d274a5b

Browse files
authored
fix(@cypress/react): throw if using Next.js swc-loader without nodeVersion=system (#18686)
1 parent a3fab73 commit d274a5b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

npm/react/plugins/next/checkSWC.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Configuration } from 'webpack'
2+
3+
export function checkSWC (
4+
webpackConfig: Configuration,
5+
cypressConfig: Cypress.Config,
6+
) {
7+
const hasSWCLoader = webpackConfig.module?.rules.some((rule) => {
8+
return rule.oneOf?.some(
9+
(oneOf) => (oneOf.use as any)?.loader === 'next-swc-loader'
10+
)
11+
})
12+
13+
if (hasSWCLoader && cypressConfig.nodeVersion !== 'system') {
14+
throw new Error(`Cypress requires "nodeVersion" to be set to "system" in order to run Next.js with SWC optimizations.
15+
Please add "nodeVersion": "system" to your Cypress configuration and try again.`)
16+
}
17+
18+
return false
19+
}

npm/react/plugins/next/findNextWebpackConfig.js

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

89
async function getNextWebpackConfig (config) {
910
let loadConfig
@@ -38,6 +39,8 @@ async function getNextWebpackConfig (config) {
3839

3940
debug('resolved next.js webpack config %o', nextWebpackConfig)
4041

42+
checkSWC(nextWebpackConfig, config)
43+
4144
return nextWebpackConfig
4245
}
4346

0 commit comments

Comments
 (0)