-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Uncaught Invariant Violation: 4.3.1 -> 5.0.1 w/ monorepo use of shared components #6769
Comments
This is a symptom of what I want to solve with #6755. Unfortunately, this isn't actually a bug with this library. You have two copies of react-router, one from the host project and one from the guest project. AFAIK, there isn't a way to resolve this when using a link. This is a "bug" of npm, essentially. |
Isn’t this related to not having the same context due to importing from different packages? |
Yes, the context pair has to be the exact same instance. |
I solved this issue using a Webpack alias in your client App. That way, when your shared packages library imports anything from Like this:
|
You're basically saying no one can create a library that includes the Link component from I thought 5.x was supposed to be fully 4.x compatible, and the only reason for the major version bump was so you could start pinning versions |
Webpack Externals is probably the correct answer here for library creators. I will report back with my results
|
^ it worked. If you are publishing a library with rrd involved, make sure it is exported as an external in webpack |
New bug when upgrading from 4.3.1 -> 5.0.1
Version
5.0.1
Steps to reproduce
Using a monorepo or
npm link
for local development with a shared components package that contains a component which importsreact-router-dom
and contains aNavLink
the application breaks withError: Invariant failed: You should not use <NavLink> outside a <Router>
.I've proved this by moving the shared components package into the
node_modules
of the project using the shared components and all works fine.Expected Behavior
I should be able to
npm link
a local package that contains components that import their ownreact-router-dom
to useNavLink
without any issues.Actual Behavior
Error: Invariant failed: You should not use <NavLink> outside a <Router>
The text was updated successfully, but these errors were encountered: