Skip to content
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

Closed
crobinson42 opened this issue Jun 7, 2019 · 3 comments

Comments

2 participants
@crobinson42
Copy link

commented Jun 7, 2019

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 imports react-router-dom and contains a NavLink the application breaks with Error: 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 own react-router-dom to use NavLink without any issues.

Actual Behavior

Error: Invariant failed: You should not use <NavLink> outside a <Router>

Note: rolling back to 4.3.1 resolves this issue.

@timdorr

This comment has been minimized.

Copy link
Collaborator

commented Jun 8, 2019

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.

@timdorr timdorr closed this Jun 8, 2019

@crobinson42

This comment has been minimized.

Copy link
Author

commented Jun 8, 2019

Isn’t this related to not having the same context due to importing from different packages?

@timdorr

This comment has been minimized.

Copy link
Collaborator

commented Jun 8, 2019

Yes, the context pair has to be the exact same instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.