Jest can't resolve module
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
Having such require syntax in sources cause jest error:
const resBundle = require(
'i18next-resource-store-loader!i18n/locales/index.js'
);
Error:
Test suite failed to run
Cannot find module 'i18next-resource-store-loader!i18n/locales/index.js' from 'i18n.js'
...
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
What is the expected behavior? I want to run my tests !
Please provide your exact Jest configuration
"jest": {
"coverageDirectory": "./coverage/",
"collectCoverageFrom": [
"src/**/*.js"
],
"moduleNameMapper": {
"\\.(scss|less)$": "identity-obj-proxy"
},
"modulePaths": [
"<rootDir>/src/"
],
"setupFiles": [
"<rootDir>/src/__mocks__/localStorageMock.js"
]
}
Is there any workarounds ?
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Jest gives `Cannot find module` when importing components ...
This Workaround: Using "moduleNameMapper" in your jest configuration will make test-resolve work as expected:
Read more >jest: configuring jest to resolve modules - code-comments
A common pattern within Javascript applications is to use Webpack or Typescript to treat internal directories as modules so that they can be ......
Read more >Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >Configuring Module Resolution On Typescript and Jest
Jest needs a way to figure out how to resolve the modules. We use the moduleNameMapper property to specify module resolution using regular...
Read more >Webpack and Jest v0.36 Upgrade Guide
Additionally, Jest now uses Node as the default test envirmonment ... with problems: Error: Module not found: Error: Can't resolve 'net' in ...
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
See https://facebook.github.io/jest/docs/en/webpack.html
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
No you’re not, you’re trying to use webpack specific syntax outside of webpack, and I linked to the relevant docs