Skip to content

Commit

Permalink
fix(@cypress/react): throw if using Next.js swc-loader without nodeVe…
Browse files Browse the repository at this point in the history
…rsion=system (#18686)
  • Loading branch information
ZachJW34 committed Nov 1, 2021
1 parent a3fab73 commit d274a5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions npm/react/plugins/next/checkSWC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Configuration } from 'webpack'

export function checkSWC (
webpackConfig: Configuration,
cypressConfig: Cypress.Config,
) {
const hasSWCLoader = webpackConfig.module?.rules.some((rule) => {
return rule.oneOf?.some(
(oneOf) => (oneOf.use as any)?.loader === 'next-swc-loader'
)
})

if (hasSWCLoader && cypressConfig.nodeVersion !== 'system') {
throw new Error(`Cypress requires "nodeVersion" to be set to "system" in order to run Next.js with SWC optimizations.
Please add "nodeVersion": "system" to your Cypress configuration and try again.`)
}

return false
}
3 changes: 3 additions & 0 deletions npm/react/plugins/next/findNextWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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')
const { checkSWC } = require('../../dist/next/checkSWC')

async function getNextWebpackConfig (config) {
let loadConfig
Expand Down Expand Up @@ -38,6 +39,8 @@ async function getNextWebpackConfig (config) {

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

checkSWC(nextWebpackConfig, config)

return nextWebpackConfig
}

Expand Down

0 comments on commit d274a5b

Please sign in to comment.