Utilizing both haste and moduleNameMapper config options causes Jest's module resolution to fail.
- Clone the test case repository.
yarn installyarn test
The required module resolves and the test passes.
https://github.com/HealthTeacher/jest-haste-module-name-mapper
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- Replacing the root directory alias
requirewith a relative require fixes the related test:const Greeter = require('./components/Greeter'); - Relocating
components/Greeter/index.web.jstocomponents/Greeter/index.jsalso fixes the related test. - The combination of
hasteandmoduleNameMapperconfig appears to cause an issue.
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)