Craco Webpack config not working with Component Testing
See original GitHub issueCurrent behavior
I’m using Craco to override CRA Webpack config and while Craco provides API to extract the overridden Webpack config, Cypress throws with the following:
Error: Cannot find module '/Users/x/dev/deepdubapp8/cypress/package.json'
Require stack:
- /Users/x/dev/deepdubapp8/node_modules/react-scripts/config/paths.js
- /Users/x/dev/deepdubapp8/node_modules/react-scripts/config/env.js
- /Users/x/dev/deepdubapp8/node_modules/@craco/craco/lib/cra.js
- /Users/x/dev/deepdubapp8/node_modules/@craco/craco/lib/features/jest/api.js
- /Users/x/dev/deepdubapp8/node_modules/@craco/craco/index.js
- /Users/x/dev/deepdubapp8/craco.config.ts
- /Users/x/dev/deepdubapp8/cypress/cypress.config.ts
- /Users/x/Library/Caches/Cypress/10.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js
- /Users/x/Library/Caches/Cypress/10.3.0/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/require_async_child.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._resolveFilename (/Users/x/Library/Caches/Cypress/10.3.0/Cypress.app/Contents/Resources/app/node_modules/tsconfig-paths/lib/register.js:75:40)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/x/Library/Caches/Cypress/10.3.0/Cypress.app/Contents/Resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:679:30)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object. (/Users/x/dev/deepdubapp8/node_modules/react-scripts/config/paths.js:28:3)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.require.extensions. [as .js] (/Users/x/Library/Caches/Cypress/10.3.0/Cypress.app/Contents/Resources/app/node_modules/ts-node/src/index.ts:1445:43)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object. (/Users/x/dev/deepdubapp8/node_modules/react-scripts/config/env.js:13:15)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.require.extensions. [as .js] (/Users/x/Library/Caches/Cypress/10.3.0/Cypress.app/Contents/Resources/app/node_modules/ts-node/src/index.ts:1445:43)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
Desired behavior
Boot Component Testing successfully.
Test code to reproduce
Extract Craco config and pass it to Cypress config:
// craco.config.ts
export const webpackConfig = createWebpackDevConfig(cracoConfig);
// cypress.config.ts
export default defineConfig({
component: {
devServer: {
framework: 'create-react-app',
bundler: 'webpack',
webpackConfig: webpackConfig,
},
},
});
Cypress Version
^10.3.0
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Create craco devServer preset #21952 - cypress-io ... - GitHub
The devServer for craco is located in @cypress/react/plugins. ... webpack config so as to allow the frameworks webpack config to work with CT...
Read more >Craco does not work properly with react-scripts@5.0.0
After upgrading react-scripts to v5, craco start does not work properly. App starts with no error but in browser, there is a blank...
Read more >@craco/craco - npm
CRACO allows you to enjoy the recognizable project structure of CRA while changing detailed configuration settings of each component. Notes on ...
Read more >Use in create-react-app - Ant Design
We are successfully running antd components now, go build your own application! Test with Jest. create-react-app comes with jest built in. Jest does...
Read more >Unit testing React components in Cypress without CRA and ...
I had to go through some hassle to get that working with a custom webpack configuration, but it's finally working, and here is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@vfritzon Awesome! your
cypress.config.ts
works for me. Thank you for sharing your solution.@xanderfehsenfelddelhivery
I’ve got it to work with this workaround
cypress.config.ts
:Some relevant dependencies and their versions: