I use react-router-dom for routing in my React application. Part of my app extracted in another package. List of dependencies looks like this:
react-router-dom
React
In my case, this error was caused due to mixing up usage of things (withRouter, MemoryRouter) from react-router and react-router-dom. By using only things from react-router-dom, the invariant error vanished. Hope this helps anybody.