question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest should resolve its dependencies from its own location rather than rootDir

See original GitHub issue

Create 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:open
  • Created 5 years ago
  • Reactions:28
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
SimenBcommented, Apr 3, 2018

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 the Resolver.findNodeModule stuff for them.

2reactions
dspacejscommented, May 6, 2020

Running into this issue and not sure how to solve it. Anyone know what to do?

I’ve installed redux-actions, which has its own reduce-reducers dependency. Now after installing reduce-reducers for my project, it’s causing errors (because redux-actions expects reduce-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found