What is a peer dependency and what is the problem with it?
Peer dependencies are a specific kind of dependencies really useful for reusa...
For further actions, you may consider blocking this person and/or reporting abuse
The
yarn link
implementation will, from the v2 onward, be able to properly follow peer dependencies. So if you're developingreact-foo
which has a peer dependency onreact
, you'll just have to go into your application, runyarn add react
,yarn link ~/react-foo
, and you'll be ready to go.Really nice to hear Maël! I can't wait to test yarn v2. Is there an alpha version available or something similar?
We're developing it over at github.com/yarnpkg/berry - it's usable, but still developer preview for now 🙂
Is there a way to get this to work with other peer dependencies? It works great when it's just
react
, but I have several peer dependencies (such asreact-redux
) which is causing conflicts. I've been messing around with this a lot and I'm having trouble getting it to work.You tried to do the same trick described in the article for
react
(linked module dependency directly into your host app) ? I agree this is a bit messy. You can use yarn v2 to fix this problem (I guess). See Maël Nison's comment on this article. He explains how it works in yarn v2 and where you can install this new version 👍Oh that's a better solution, thanks. I'd use that but my team uses NPM. I ended up just installing the peer dependencies for our library into
peer_deps/node_modules
so it's not picked up by the app but can still be used by the library during development.Unfortunately, the linking solution for the React library did not work for me. The link seemed to set up just fine, but when I launched the consumer app I got the dreaded "Invalid hook call," same as before setting up the link to react.
It didn't work for me too in the beginning, but after I deleted the node_modules in the library, reinstall and did the linking again between the library and parent App, it works. Maybe something you could try.
I do know to try this, but unfortunately it does not resolve the problem. I have run into this again while trying to develop a library. Very frustrating and link simply doesn't work to resolve this at all.
Do you have experience with this error?
Thanks in advance!
Hi Juan David Nicholls Cardona. Did you have this message using
install-peer-deps
in theprepare
script ?yes, but only using npm, it was fixed by using yarn instead, thanks!
It's unfortunate that someone would make a package that only works with yarn! We can't just change our standards to use yarn just for one library. :(
Okay, I got it to work with npm by appending the force flag (-f), so my script command is now "install-peers -f". Seems to be a bug in the library and there is an open github issue already about this.
You can use "postinstall": "install-peers", this command run after the package is installed.
This work for me.
Thanks you, i found that comment from Dan but i really don't understood how to do it
So it works fine for you now?
Yes! It works!
I think a simpler solution is to add the peerDeps also as devDeps. I don't know if it is the best one, but is way simpler than what you propose here.
That is one way to do it. One disadvantage, though, is having to manually keep dev and peer in sync. The advantage is not needing another library to install peers. So it's a matter of which trade-off you prefer. Myself, I'm more worried about the error-prone nature of manually duplicating two lists in my package.json so I'm standardizing on just going and using install peers. But I also understand why someone would want to avoid yet another library.
Thank you for sharing! I'll test it and a note about it in the article 👌
Thanks for the useful guide! The original package read me didn't say much about this usage.
🙌
If its failing in the tests, put 'react' in both peer-dependencies and dev-dependencies.