-
-
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
Resolving peer modules when using local linked packages #2447
Comments
When debugging, I found the logic where modules get resolved is in Jest's |
Just curious – have you tried linking with npm instead of yarn? |
@thymikee Just tried and still having the same issue... Npm version 3.10.8 |
👍 I'm having the same problem when running tests against packages linked via lerna. I believe it prevents tracking coverage of linked packages as well. |
@voliva @thymikee I just figured out this is a bug in the node-resolve package. I have a PR for a fix that seems to fix all the problems I've had with jest & linked packages here. To fix temporarily, you can add an {
"dependencies": {
"browser-resolve": {
"version": "1.11.2",
"from": "browser-resolve@>=1.11.2 <2.0.0",
"resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.11.2.tgz",
"dependencies": {
"resolve": {
"version": "https://s3.amazonaws.com/waldo-public/resolve-1.2.0-patched.tar.gz",
"from": "[email protected]",
"resolved": "https://s3.amazonaws.com/waldo-public/resolve-1.2.0-patched.tar.gz"
}
}
},
"resolve": {
"version": "https://s3.amazonaws.com/waldo-public/resolve-1.2.0-patched.tar.gz",
"from": "resolve@>=1.2.0 <2.0.0",
"resolved": "https://s3.amazonaws.com/waldo-public/resolve-1.2.0-patched.tar.gz"
}
}
} |
@L8D have you had any progress with getting your fix merged? |
Until this is fixed, a workaround is to add a jest config remapping references to the linked module to the parent version. In
This produces the expected output in @voliva's test repo. |
Another solution will be:
And I might open a pull request to make it default behaviour |
Sorry, but I'm curious why this was closed? Was there a resolution? Because I'm having this issue with jest 24.9.0 and have tried every solution suggested in this thread. Nothing works. My linked module can't find @material-ui/core within a jest test (but no problems when running it linked in the linked app). Have we just given up on doing this? If so, this makes Jest useless to me. |
@SevenZark the |
Apologies, I neglected to mention something very important, which is that I'm using create-react-app and therefore cannot alter things with moduleNameMapper. I realize that's a big omission. |
Jest tests fail locally when `yarn link` points to a lib with peer dependencies. This map configuration adds redirection to import these dependencies from <rootDir>/node_modules instead of the linked modules folders. jestjs/jest#2447 (comment)
Just out of curiosity, what's the purpose of starting and ending signs? (I mean For some context, I had failing tests with the following settings.
Output looked like the below.
Then I changed my setting into
All of a sudden, tests passed as if nothing has happened. Does anyone knows the difference between |
That said, this is a really old issue and the linked reproduction in the OP is deleted, so I'll close this. If the fix in #2447 (comment) is correct, then this issue is fixed as we do call If there are still problems with this, please open up a new issue with a reproduction |
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. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Having the following structure:
When
MyLibrary
requiresMyDependency
, it loads it fromMyModule/node_modules/MyLibrary/node_modules
folder if it's available, when it should get the peer version.The problem that this issue arises is an inconsistent behaviour when using local linked packages, because when installing through
yarn install
MyLibrary won't contain a node_modules folder, but when doing throughyarn link MyLibrary
it will, as it's a soft link.In my case, MyDependency is
rx
, andMyLibrary
creates a Reactive extension by defining some methods onRx.Observable.prototype
. When running jest without any local link, or when through nodejs, this works properly, but when running through jest withMyLibrary
locally linked,Rx.Observable.prototype
gets wiped whenrx
is loaded a second time.If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can
yarn install
andyarn test
.https://github.com/voliva/jestpeer
You must locally link the modules by:
If you run
yarn start
, that's just node running the app, you should get:If you run
yarn test
, that's jest running the test, you should get:Notice how while when running through node MyLib doesn't get loaded twice, while when running through Jest it does
What is the expected behavior?
yarn test
should outputPlease provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Default jest configuration, Jest 18.0.0, node 6.9.1, yarn 0.19.0, Windows 10 64bit.
The text was updated successfully, but these errors were encountered: