Skip to content
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

Module resolution fails when using both haste and moduleNameMapper config options #7086

Closed
dcalhoun opened this issue Oct 1, 2018 · 6 comments
Labels

Comments

@dcalhoun
Copy link

dcalhoun commented Oct 1, 2018

🐛 Bug Report

Utilizing both haste and moduleNameMapper config options causes Jest's module resolution to fail.

To Reproduce

  1. Clone the test case repository.
  2. yarn install
  3. 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 to components/Greeter/index.js also fixes the related test.
  • The combination of haste and moduleNameMapper 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)
@dcalhoun dcalhoun changed the title Module resolution to fails when using both haste and moduleNameMapper config options Module resolution fails when using both haste and moduleNameMapper config options Oct 1, 2018
@grosto
Copy link
Contributor

grosto commented Nov 30, 2018

I can try to tackle this one if help is still needed

@dcalhoun
Copy link
Author

@grosto still an active bug from what I know. Thank you!

@grosto
Copy link
Contributor

grosto commented Nov 30, 2018

@dcalhoun it seems to be fixed with this PR #7312.

@dcalhoun
Copy link
Author

@grosto looks like you may be correct. I can't re-test my original reproduction example right now, but I'll try to do so later.

@rickhanlonii
Copy link
Member

Going to optimistically close, if it's still an issue let us know and we'll re-open 👍

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants