react-router: bug: react router dom 4.3.1 pulling react-router 4.4.0 changes after latest publish
I’m seeing the following error:
Warning: Please use `require("react-router").Router` instead of `require("react-router/Router")`. Support for the latter will be removed in the next major release.
console.error node_modules/react-router-dom/node_modules/react-router/warnAboutDeprecatedCJSRequire.js:17
Warning: Please use `require("react-router").MemoryRouter` instead of `require("react-router/MemoryRouter")`. Support for the latter will be removed in the next major release.
console.error node_modules/react-router-dom/node_modules/react-router/warnAboutDeprecatedCJSRequire.js:17
Warning: Please use `require("react-router").Route` instead of `require("react-router/Route")`. Support for the latter will be removed in the next major release.
console.error node_modules/react-router-dom/node_modules/react-router/warnAboutDeprecatedCJSRequire.js:17
Warning: Please use `require("react-router").Prompt` instead of `require("react-router/Prompt")`. Support for the latter will be removed in the next major release.
console.error node_modules/react-router-dom/node_modules/react-router/warnAboutDeprecatedCJSRequire.js:17
Warning: Please use `require("react-router").Redirect` instead of `require("react-router/Redirect")`. Support for the latter will be removed in the next major release.
console.error node_modules/react-router-dom/node_modules/react-router/warnAboutDeprecatedCJSRequire.js:17
Warning: Please use `require("react-router").StaticRouter` instead of `require("react-router/StaticRouter")`. Support for the latter will be removed in the next major release.
console.error node_modules/react-router-dom/node_modules/react-router/warnAboutDeprecatedCJSRequire.js:17
Warning: Please use `require("react-router").Switch` instead of `require("react-router/Switch")`. Support for the latter will be removed in the next major release.```
Inside the package.json file of react-router dom:
```"dependencies": {
"history": "^4.7.2",
"invariant": "^2.2.2",
"loose-envify": "^1.3.1",
"prop-types": "^15.5.4",
"react-router": "^4.3.1",
"warning": "^3.0.0"
},```
It's downloading 4.4.0 due to this.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 39 (15 by maintainers)
Commits related to this issue
- React bug weird issue with links not working in react https://github.com/ReactTraining/react-router/issues/6630 — committed to trevormduncan/golang-url-shortener by trevormduncan 5 years ago
- Okta Integration - Bring Okta OAuth as an available option - Edited package.json for react bug + https://github.com/ReactTraining/react-router/issues/6630 — committed to trevormduncan/golang-url-shortener by trevormduncan 5 years ago
- fix : lock react-router dependencies to 4.3.1 since 4.4.0 introduce breaking changes https://github.com/ReactTraining/react-router/issues/6630 — committed to ONEARMY/community-platform by BenGamma 5 years ago
- don't use react-router's private API Pulling `router.history` off `context` is a bad idea. As noted at https://github.com/ReactTraining/react-router/issues/6630#issuecomment-473946064, that's the int... — committed to folio-org/stripes-core by zburke 5 years ago
- don't use react-router's private API (#647) Pulling `router.history` off `context` is a bad idea. As noted at https://github.com/ReactTraining/react-router/issues/6630#issuecomment-473946064, that'... — committed to folio-org/stripes-core by zburke 5 years ago
- Okta Integration - Bring Okta OAuth as an available option (#128) - Edited package.json for react bug + https://github.com/ReactTraining/react-router/issues/6630 — committed to mxschmitt/golang-url-shortener by trevormduncan 5 years ago
Quick update for anyone who’s watching this issue: I just unpublished 4.4.0 and re-released it as 5.0.0. v5 should be out as soon as https://travis-ci.org/ReactTraining/react-router/jobs/507926860 finishes.
Can confirm this bug with both yarn 1.15.2 and npm 6.9.0.
Curiously, codesandbox doesn’t have this issue.
Reproduction: https://github.com/StringEpsilon/react-router-bug-6630 (
npm i; npm run start)Edit: As a workaround, you can simply add
or more explicetly:
to your package.json.
Apologies for the breakage here. You should not use
react-router-domversion 4.3.1 withreact-router4.4.0. I assumed (incorrectly) that when people started usingreact-router4.4.0 they would also be usingreact-router-dom4.4.0, but as @pshrmn pointed outreact-router-domisn’t pinned toreact-router4.3.1, as it probably should be.There are 2 things you can do:
react-routerversion to 4.3.1 (usingnpm i react-router@4.3.1) so that you’ll have the correct version orreact-router-domandreact-routerand just reinstall. Assuming you have{ "react-router-dom": "^4.3.1" }in yourpackage.json, you’ll automatically get version 4.4.0 and everything should work as before (with warnings for deprecated stuff).Honestly, I’m kind of stumped about how to really “fix” this situation. Options are:
npm i react-router-dom@nextin the interim.I’m honestly not sure which path is less pain for people at this point. (b) is kinda weird because usually major version bumps are done only for breaking changes (though one could possibly make the argument that using the new context API is a breaking change), but I think it might be the best option. With (b) everyone who hasn’t already hit this bug will never need to know about it, and people who are interested in using the new stuff will have a path forward.
Any other options y’all can think of?
@mjackson I think that I have this scenario, do you have a tip on how to solve this?
Another option is unpublish 4.4.0 and re-release it as 5.0.0. I’d vote for that. A version is just a number; it doesn’t have to mean anything.
Just want to point this out in case it’s related to this. I think it’s an undocumented change. After updating
react-routerandreact-router-domto4.4.0I’m getting a new error:Has something changed in regards to this? I tried to find a changelog and found changes.md but it doesn’t address
4.4.0. I do understand that context.router is “experimental”. I can see that you referenced this above:For context this is part of a Google Analytics automation I made:
Used like this:
thanks for the info @mjackson!! I was wondering if I should kill you in a snap or torture you some months… ❤️
Just want to add this here for others that may be googling the error as I did. The specific error I got was:
And I managed to fix it using the
resolutionsmethod mentioned above (thanks @StringEpsilon!)Temporarily fixed by running:
This updates the dependencies in
package-lock.jsonwithout changingpackage.json.@timdorr Sadly, it didn’t do the trick.
@mjackson Re-releasing 4.3.1 as 4.5 would just re-introduce this bug for people who already migrated to 4.4, as 4.4 also doesn’t have a properly pinned react-router version as a dependency. And while 4.4 is backwards compatible, 4.4 has new features that 4.3.1 didn’t have. Those would break (such as route path arrays).
I suggest pinning this issue and maybe adding something to the readme and clarifying the changelog and documentation and adding the resolutions workaround to it.
It doesn’t solve the issue, but it’s better than creating a new round of breakage.