0

I wanted to implement component testing in CRA, but I get an error during configuration:

Your configFile threw an error from: cypress/config/myConfig.config.ts

We stopped running your tests because your config file crashed.

../../Library/Caches/Cypress/12.12.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/helpers/createReactAppHandler.js:70:15
  68 |     }
  69 |     catch (err) {
> 70 |         throw new Error(`Failed to require webpack config at ${webpackConfigPath} with error: ${err}`);
     |               ^
  71 |     }
  72 | }
  73 | exports.cypressGlobals = ['cy', 'Cypress', 'before', 'after', 'context'];
  74 | function addCypressToWebpackEslintRulesInPlace(webpackConfig) {

Error

Cypress 12.12.0

I have reinstalled Cypress and I keep getting the same error. Has anyone had a similar error?

Johnny
  • 1
  • 2

1 Answers1

1

The package @cypress/webpack-dev-server which you are using in your config is looking for the file <project-root>/node_modules/react-scripts/config/webpack.config.js.

It looks like you have used the eject script which removes the <project-root>/node_modules/react-scripts folder completely.

If you wish to stay ejected, you can add webpack.config.js to the project root instead.

This is the relevant piece of code (from @cypress/webpack-dev-server):

webpackConfigPath = require.resolve('react-scripts/config/webpack.config.js', {
  paths: [devServerConfig.cypressConfig.projectRoot],
})

When require.resolve('react-scripts/config/webpack.config.js') fails (after eject) the path at devServerConfig.cypressConfig.projectRoot is used - which is just the project folder if you aren't using a mono-repo.