Module resolution fails when using both haste and moduleNameMapper config options
See original GitHub issue🐛 Bug Report
Utilizing both haste
and moduleNameMapper
config options causes Jest’s module resolution to fail.
To Reproduce
- Clone the test case repository.
yarn install
yarn test
Expected behavior
The required module resolves and the test passes.
Link to repl or repo (highly encouraged)
https://github.com/HealthTeacher/jest-haste-module-name-mapper
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS 10.14
CPU: x64 Intel(R) Core(TM) i7-4750HQ CPU @ 2.00GHz
Binaries:
Node: 10.8.0 - ~/.asdf/shims/node
Yarn: 1.10.1 - /usr/local/bin/yarn
npm: 6.2.0 - ~/.asdf/shims/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
Notes
- Replacing the root directory alias
require
with a relative require fixes the related test:const Greeter = require('./components/Greeter');
- Relocating
components/Greeter/index.web.js
tocomponents/Greeter/index.js
also fixes the related test. - The combination of
haste
andmoduleNameMapper
config appears to cause an issue.
Error Output
FAIL __tests__/index.test.js
● Test suite failed to run
Configuration error:
Could not locate module ~/components/Greeter mapped as:
/Users/username/Sites/oss/jest-haste-module-name-mapper/components/Greeter.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^~\/(.*)/": "/Users/username/Sites/oss/jest-haste-module-name-mapper/$1"
},
"resolver": null
}
> 1 | const Greeter = require('~/components/Greeter');
| ^
2 |
3 | // Replacing the above `require` with below fixes the related test
4 | // const Greeter = require('./components/Greeter');
at createNoMappedModuleFoundError (node_modules/jest-resolve/build/index.js:411:17)
at Object.<anonymous> (index.js:1:25)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
jest --watch hangs silently if moduleNameMapper cannot ...
I'm having the same issue, with the moduleNameMapper jest --watch hangs. Removing the moduleNameMapper it works (well, runs the tests and fails ......
Read more >Configuring Jest
This option allows the use of a custom global setup module, which must export a function (it can be sync or async). The...
Read more >`moduleNameMapper` settings in jest.config.js doesn't work ...
tsconfig-paths-jest is not usable in Jest >23. For current Jest 26 I got it working via: ...
Read more >jest-haste-map | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >Setting up a Monorepo with React Native You.I and Yarn - G2i
Our goal is to have two apps in the same repository, and allow these two apps to use the same modules inside a...
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
Going to optimistically close, if it’s still an issue let us know and we’ll re-open 👍
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.