Jest should resolve its dependencies from its own location rather than rootDir
See original GitHub issueCreate React App users bumped into this issue recently. A third party package started depending on jest-validate
, and that caused npm to hoist jest-environment-node
to the top of the app tree. Unfortunately, Jest resolves environment package from the project root instead of from its own Node module location so as a result, it loads the wrong (hoisted) jest-environment-node
.
I think the jest
package should resolve any own dependencies from its own location (just like Node resolution works) rather than from the project root folder.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:28
- Comments:19 (5 by maintainers)
Top Results From Across the Web
Configuring Jest
Instead of including jest.useFakeTimers() in each test file, you can enable fake timers globally for all tests in your Jest configuration: JavaScript ...
Read more >Resolve file paths in Jest - webpack - Stack Overflow
When I run jest command in npm, I get an error saying 'Cannot find module ...`. How can I resolve file paths when...
Read more >Configuration | ts-jest - Huafu
ts-jest configuration is done within Jest configuration object. This latest can be in package.json under the jest property, or in its own jest.config.js ......
Read more >Configuring Jest compiled - w3resource
You should use the <rootDir> string token to include the path to your project's root directory to prevent it from accidentally ignoring all...
Read more >A guide through The Wild Wild West of setting up a mono repo ...
We will be using TypeScript, Yarn workspaces, Lerna, and Jest. The ... Now that all the dependencies are installed, let's continue with the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
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
Nice detective work, this is indeed a subtle and annoying bug.
I think it makes sense to special case
(jest-environment-)node
and(jest-environment-)jsdom
and skip theResolver.findNodeModule
stuff for them.Running into this issue and not sure how to solve it. Anyone know what to do?
I’ve installed
redux-actions
, which has its ownreduce-reducers
dependency. Now after installingreduce-reducers
for my project, it’s causing errors (becauseredux-actions
expectsreduce-reducers
to be a different version).This works fine in my app and is therefore set up correctly, it’s just that the Jest tests are now failing because Jest is loading the wrong version.
For now I’ve just installed the version
redux-actions
expects as a workaround, but I think Jest should handle module resolution the same way Node does.