-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Jest cache incorrectly resolving modules #4092
Comments
I'm having the same problem too! |
I've been tinkering with this a bit more and found some additional behavior that might be helpful. If In my demo repo, in {
"content": "Here is a nested component's Canadian content"
}
Clear the jest cache. I did this by deleting a directory at Run Jest once to prime the cache. Run Jest again and see that the tests still pass. If you investigate the cache directory that's been recreated, you'll see there are two instances of files called [1] If anyone is reading along, you can find your cache directory by running |
same problem. any ideas? |
@mmahalwy - may want to check that your NODE_PATH environment variable doesn't contain any non-existent directories (see #4453 (comment)) |
this seems to finally be resolved with "jest": "^22.3.0", |
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. |
Before creating an issue please check the following:
✅
"jest": "^20.0.4",
✅ so.many.times.
--no-cache
to see if that fixes the problem you are experiencing.✅ tried it.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
20.0.421.0.17.4.08.1.30.27.51.3.24.0.55.6.0MacOS Sierra 10.12.5 (16F73)MacOS High Sierra 10.13.2Repo with reproduction steps here:
https://github.com/imjared/jest-resolver-failure-repro
Description
We've been having issues with (what seems to be) Jest's module resolver and how it interacts with Jest's cache.
Our
.babelrc
uses the module-resolver plugin so we can use paths relative to oursrc
directory (effectively the root of our project) rather than from each file. For example,import Bar from '../../components/foo/bar'
might end up beingimport Bar from 'components/foo/bar'
.This test case is reduced to show our i18n helper that lives in
src/utils/i18n.js
. We use this in our translation JSON files to provide fallbacks for translations when a locale may be missing or a locale like Germany might provide translations for Austria and Switzerland.When we run tests, our i18n helper runs as expected as long as it exists at what would be the same relative path. For example, in this repo, the path from
Component1/translations/index.js
to thei18n
module would be:import { i18n } from '../../../utils/i18n.js';
When we test a component that has a different relative path, the i18n module can not be found. For example, the path from
Component2/NestedComponent/translations/index.js
to thei18n
module would be one level deeper:import { i18n } from '../../../../utils/i18n.js';
This causes tests to fail.
Reproduction
yarn
to install dependencies. Ensure you have jest-cli installedjest
oryarn test
. The first test run primes the Jest cache so tests should pass fine. Run tests again.Expected Behavior:
Tests still pass. Paths resolve as they should.
Actual Behavior:
Tests fail. The error is as follows:
It seems that the module can't be found because the path that's four directories up is actually the path used from the NestedComponent's translation index file.
Running the tests again with either
jest --no-cache
oryarn test:nocache
should pass.The text was updated successfully, but these errors were encountered: