-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Support CRA config overrides via react-app-rewired and customize-cra #9688
Comments
We don't have a react-scripts rewired example, it probably would require creating its own preprocessor loader, like did for react-scripts and webpack and others. |
Ok so there is no solution for now to use aliases ? |
I don't think so. What would be useful is to have an example repository set up that shows your use case (simple hello world with rewired and aliases), that we could fork and play with to see how to implement this. |
project is attached as zip file last line of the initial coment can add one more time: |
Or shall i open a git repo? |
Do you mind if we include that app in this repo? |
Of course you can add it to this repo, if it will be useful for someone. Hope for me as well) |
so really there are three issues here:
|
@bahmutov this remains as it was - no way to feed cypress the |
Does this situation changes after v10? I have similar problem with my repo here: https://github.com/MohoiNad/cypress-issue So my cypress test failed, but testing library not |
I had the same issue, my solution was the following cypress.config.js file:
Note that I only tested the component config as I didn't have any e2e tests setup |
@binginsin Thanks for sharing your solution. Unfortunately it didn't work for me out of the box, but helped me understanding the problem and creating the final setup. It looks like this: import { defineConfig } from 'cypress';
/**
* "Rewire" the webpack config before `loadWebpackConfig` accesses it through `react-scripts`
* @see @cypress/webpack-dev-server/dist/helpers/createReactAppHandler.js:41
*/
process.env.NODE_ENV = 'test';
process.env.BABEL_ENV = 'test';
require('react-app-rewired/config/webpack.config')('development');
export default defineConfig({
component: {
devServer: {
framework: 'create-react-app',
bundler: 'webpack',
},
},
}); |
Thank you so much @bencergazda! 🚀 ❤️ I've been trying to troubleshoot webpack errors while running a component test for more than 3 hours, and I finally found this issue and its answer, which completely solved my problem! My error was in relation to using absolute paths inside the component that was being tested.
In my case, Also, I replaced "test" with "development" in The TypeScript compiler was reporting an error when assigning a value to a read only variable, which forced me to use @ts-ignore. // @ts-ignore
process.env.NODE_ENV = 'development'; |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
I have set create-react-app with react app rewired absolute path like:





config-overrides.js:
also configured tsconfig.paths.json to use aboslute paths:
I also configured cypress to to start through react-app-rewired(overrides react-scripts without ejecting):
package.json:
I import in MyComponentToTest.tsx another component with absolute path :
MyComponentToTest.tsx:
when i run yarn cypress:open and run cypress/integration/App.spec.tsx it work as expected.
However when i try to run component test MyComponentToTest.tsx i get error that it was unable to solve the path :
My question is how i can learn cypress to use absolute paths for unit testing too?
my example app:
cypres-unit-test.zip
The text was updated successfully, but these errors were encountered: