-
-
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 should resolve its dependencies from its own location rather than rootDir #5913
Comments
I guess the problem is that an environment might need to be searched for in the project folder if the project explicitly specifies it. Perhaps it's worth including the project folder if environment exists in |
Nice detective work, this is indeed a subtle and annoying bug. I think it makes sense to special case |
Rather than special module resolution logic, maybe relying on explicit versions of peer packages might be the best way to go? Declaring all dependencies and strictly sticking to semver should also work, but semver is a lot harder to follow in monorepos according to my own experience. I've also had a similar bug with jest recently - since it's a dev dependency I wouldn't mind the lack of deduplication due to exact module resolution. |
I think we want to avoid |
I think this:
could be confusing for people who specifically want to pin their versions (e.g. to avoid a bug). It would make more sense to me if Jest only searched the app folder when the app's |
We can do that. Should we only check for |
Oh man. This is why I hate configuration shortcuts 😄 |
@cpojer @aaronabramov thoughts? |
I think I expect that if I have If I don't specify it in my Finally, if I specify some other environment (not In other words, the only case in which I want Jest to resolve env from its own |
So if the env is one of the two shipped with jest, look for them in root deps, if there use them, otherwise resolve from root? Unknown envs are resolved from root no matter what. Seems reasonable to me :) Should we just care about |
Any explicit mention seems like fair game to try resolving from app root (IMO). |
I proposed a different solution in the comments for PR #6145. The fundamental issue here seems to be that the Jest configuration specifies the test environment as a naive package name, but the package version is determined by brittle heuristics that vary between package managers. It completely falls apart for my situation where we need two different versions of Jest to be installed side-by-side. Tuning the brittle heuristics seems like a step in the wrong direction. The Updating |
@gaearon one thing you can do to fix this is give Jest absolute paths (e.g. doing |
Can this issue be looked into again? |
Running into this issue and not sure how to solve it. Anyone know what to do? I've installed 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 |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
We should still do this, probably |
Hi, is there any chance this will be looked at? |
PR very much welcome 🙂 I don't have any plans to work on this myself, but happy to review PRs |
Create React App users bumped into this issue recently. A third party package started depending on
jest-validate
, and that caused npm to hoistjest-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.The text was updated successfully, but these errors were encountered: