-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting up Cypress using webpack 5 and react-scripts #18992
Comments
I was able to reproduce with the following: package.json {
"scripts": {
"cy:open:ct": "cypress open-ct"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@cypress/react": "^5.10.3",
"@cypress/webpack-dev-server": "^1.7.0",
"babel-loader": "^8.2.3",
"cypress": "^9.0.0",
"react-scripts": "^4.0.3",
"webpack": "^5.64.1"
}
} webpack.config.js const path = require('path')
module.exports = {
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
}
},
]
},
} cypress/plugins/index.js const injectDevServer = require('@cypress/react/plugins/react-scripts')
module.exports = (on, config) => {
injectDevServer(on, config)
return config
} Then running If I change the webpack dependency to |
Having the same issue but with react-scripts v5 which uses webpack 5 under. Any workarounds? |
Looks like |
@FelipeLahti the latest version of webpack-dev-server is 4.6.0 which supports Webpack v5 so we should be able to support v5. Looks like You can check out a (somewhat) working version of Cypress and react-scripts@5 here. You can clone the repo, check out the |
The code for this is done in cypress-io/cypress#19434, but has yet to be released. |
@FelipeLahti that PR was merged and released in @cypress/react@5.12.0. Have your tried it with the latest? |
@ZachJW34 Looks like the release for @cypress/react@5.12.1 didn't include that change. |
@FelipeLahti the compare shows the commit for cra-5 support "feat: support create-react-app v5 (#19434)", it's down at the bottom. The changes were indeed released as part of |
Ok. Getting this now on a fresh installation #19674 |
That is my use case also, it started today. Old installation/yarn.lock works just fine. In a fresh project, or deleting |
I can only make this work by reverting to |
This is broken for me as well. Simply followed the official docs for React component testing. |
I create this repo here with a reproducible example with the same dependencies I have in my project.
Steps to reproduce in the repo:
Let me know if I can help |
Hey @FelipeLahti, I was hitting the same error as you, and was able to get around it by installing webpack 5 as a top level dependency in my project via:
Cypress's By installing webpack5 at the top level, the dev server will use that version instead, which will hopefully hold you over until cypress ships with native support. |
Hey @GideonShils Updated https://github.com/FelipeLahti/error-create-react-app-v5 and it's working now. Thanks! Would be good if update the docs. I'll see if I can open a PR next week |
Closing this issue, as it was addressed in #19434 |
Current behavior
I am facing an issue with setting up Cypress with webpack 5. When I run the test end-to-end It works properly, but when I run the component test (
cypress run-ct
) I got an error. Follow the errro below:What I could notice is I'm using the
react-scripts
library and it is using webpack 4 under the hood. I tried to usewebpack-5-react-scripts
but it didn't work as well.Anyone has already faced this before?
My package.json
My webpack config
My Cypress plugin
Debug logs
No response
Cypress Version
9.0.0
Package Manager
yarn
Operating system
Mac
Other
Node version: 14.18.1
Thanks in advance!
The text was updated successfully, but these errors were encountered: