storybook: Storybook v6.4 is breaking users using react-router v5
As storybook v6.4 brings react-router v6, people using v5 face breaking changes for a minor version update of storybook, which breaks semver.
Temporary solution is changing the version to ~6.3.12 instead of ^6.13.12 in the package.json file and putting "@storybook/router": "~6.3.10", in the resolution parameter of the package.json
And this breaking change is due to the storybook-addon-outline referenced in @storybook/addons-essentials. Follow the yarn why command. This package doesn’t follow the fixed version nature of other storybook packages.
=> Found "react-router@6.0.2"
info Has been hoisted to "react-router"
info Reasons this module exists
- Hoisted from "@storybook#addon-essentials#storybook-addon-outline#@storybook#addons#@storybook#router#react-router"
- Hoisted from "@storybook#addon-essentials#storybook-addon-outline#@storybook#addons#@storybook#router#react-router-dom#react-router"
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 62
- Comments: 59 (15 by maintainers)
Commits related to this issue
- Add react-router to app-web - address https://github.com/storybookjs/storybook/issues/16837 - this is temporary solution until we upgrade app to v6 of react-router — committed to Enterprise-CMCS/managed-care-review by haworku 3 years ago
- Upgrade storybook deps (#673) * Upgrade storybook deps via npx sb upgrade * Add react-router to app-web - address https://github.com/storybookjs/storybook/issues/16837 - this is temporary soluti... — committed to Enterprise-CMCS/managed-care-review by haworku 3 years ago
- M3-5585: Add Story for Navigation (#8069) ## Description This PR adds stories for all things menu related (ie. `TopMenu`, `SideMenu`, and `UserMenu`) along with mock profile data. **Update:** M... — committed to linode/manager by tiffwong 3 years ago
- Upgrade babel, storybook, and postcss dependencies * Upgrades dependencies to resolve react-dev-utils CVE. * Have to stay on v6.3.x for @storybook dependencies because of https://github.com/storybook... — committed to tmarkley/OpenSearch-Dashboards by deleted user 3 years ago
- Upgrades babel, storybook, and postcss * Upgrades dependencies to resolve react-dev-utils, browserslist, and postcss CVEs. * We have to stay on v6.3.x `@storybook` dependencies because of https://git... — committed to tmarkley/OpenSearch-Dashboards by deleted user 2 years ago
- Upgrades babel, storybook, and postcss (#1104) * Upgrades dependencies to resolve react-dev-utils, browserslist, and postcss CVEs. * We have to stay on v6.3.x `@storybook` dependencies because of ... — committed to opensearch-project/OpenSearch-Dashboards by deleted user 2 years ago
- [D&D] Rebase with Node 14 (#1236) * [Git] update PR template (#937) Update template to remove javadoc check box since we do not have any javadocs and include how to run the tests we use to verify... — committed to opensearch-project/OpenSearch-Dashboards by ashwin-pc 2 years ago
- chore(deps): explicitly add dependency on react-router needed for Storybook 6.4. c/f https://github.com/storybookjs/storybook/issues/16837#issuecomment-984006866 — committed to owid/owid-grapher by marcelgerber 2 years ago
- update storybook to 6.5.0 to solve typing issues https://github.com/storybookjs/storybook/issues/16837 — committed to grafana/pyroscope by eh-am 2 years ago
To clarify: if user wants to use typescript with
react-router-domthey will install@types/react-router-dom, which has a dependency on@types/react-routerand imports types from@types/react-router, but typescript resolves packages from@typessubfolder ofnode_modulesonly if it cant find corresponding folder in the./node_modules/. Now, when user installs any package that has a dependency onreact-router, they will getreact-routerfolder in theirnode_modulesand sincereact-router@6.xnow comes with types, you don’t need to install@types/react-routerseparately. But if you are still using@types/react-router-dom, when resolving types forreact-routertypescript will findreact-router/index.d.tsin rootnode_modulesand use it as a type definition, hence people are getting the error aboutx not foundin TS, because essentially types fromreact-router@6.xversion are being used for@types/react-router-dom@5.x. This is obviously not an issue withstorybook, just wanted to clarify why it happens when people updating to latest storybook version.FYI we’re working on a fix for this, hopefully arriving in the next few days 🤞
@shilman I don’t think there is a “good” solution, but there are a few options (none of them involve changing anything in storybook):
react-router@5.xjust for the sake of keeping rootnode_modules“clean” from latest version (probably not going to work if you want to flatten your dependencies)react-routerversion to5.x, probably not a good idea since there were breaking changes inreact-router@6.xso giving a package5.xwhen it expects6.xmight produce unpredictable result (bugs/things not working/breaking etc.)react-router@6.x, that works, but as time goes, more and more packages will update to latestreact-routerso you will need to pin more and more packages.pathsoption like this:but, if for whatever reason you will need to compile typescript code from
node_modulesthat expects to getreact-router@6.xit will fail, I do not think this is a common thing to desire, so I personally feel like this option is the bestAs for storybook, as I said, I don’t think that’s the issue within storybook, so I haven’t really given a thought to how it can be mitigated from storybook side.
Boo-yah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.32 containing PR #17294 that references this issue. Upgrade today to the
@nextNPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
as a side note, a bit disappointed react-router team released 6 a month ago before backward compatibility path is finalized https://github.com/remix-run/react-router/blob/main/docs/upgrading/v5.md
I am also facing this issue, any updates on that?
@shilman i’m also encountering this issue or a similar one. bumping to 6.4 storybook deps cause tsc typecheck errors around react-router. adding
"react-router": "^5.1.2"to deps works around it, but i’m wary of adding deps that aren’t explicitly imported in the project. perhaps the issue is for projects that use react-router-dom instead of react-router.Hi, I just update to the new storybook 6.4.19 I still using React-router-dom 5 in my app and look like its try to use react-router 6 because storybook and my CRA is getting this error
I have found this solution: https://github.com/gvaldambrini/storybook-router/issues/53#issuecomment-962399619
Works like a charm for me
@ml-devninja how is that a solution to the issue? the problem is the dependency being updated in the project, not storybook specific.
All of the proposed solutions are kind of wack… For repos that still use react-router-dom v5 Storybook’s use of v6 causes a lot of compilation errors for that repo due to reasons @MhMadHamster explained. Is the solution to wait for the v5 / v6 backwards compatibility from the React Router team?
aside from manually fixing the version of
react-routerinpackage.jsonare there any other fixes for this currently?I am also facing this issue.
Is there a way to backport it once 6.5 is still a little distant?
@shilman Are there any plans to fix it? I’m pretty sure a lot of people will not upgrade to version 6 of react-router anytime soon
react-router even recommends not to upgrade the version until they’ll release a backward-compatible version
Thanks.
The thing that I’m not seeing having been addressed above is that
@storybook/routeradded dependencies forreact-routerandreact-router-domfrom 6.3.x to 6.4.x. Here’s the situation of transitive dependencies at 6.3.x - at least for me (output fromnpm ls @storybook/router):Now with those new deps on
react-routerandreact-router-dom, all these packages transitively depend on them at version 6.x. Clearly@storybook/routeris heavily reused within the storybook packages. Other libs have solved this via peerDependencies. Yes, it means that@storybook/routeret al would need to support multiple versions ofreact-routerand friends, but it definitely saves us end-users from getting broken on minor upgrades. Is a peerDependencies solution (similar to what’s already being done forreact) worth considering here?@shilman Thanks for the fix! I was running into the react-router-dom typescript issues on 6.4, found this thread and the alpha fix and it seems to work.
@winkerVSbecks can you please update
storybook-addon-outlinedependencies to~6.3.0and publish a new patch release? we didn’t move fromstorybook-addon-outlineuntil 6.4, so currently all 6.3 users might, under some set of conditions, get 6.4 dependencies pulled in per ☝️And if I upgrade to 6.4, react-router is upgraded to v6 even though I have
react-router-dom: "^5.0.0"in my package.json.The problem is that even if I use
~to keep my dependencies on v6.3.x, @storybook-addons-essentials will bump react-router to v6.for some reason, after upgrading to the stable 6.5 version and removing lockfile, and reinstalling it worked for me. thank you 😃
any updates?
hi. i have upgraded storybook to https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.32 (issue with react-router 6 in other projects) After the upgrade, i have a problem with build-storybook. error: Field ‘browser’ doesn’t contain a valid alias configuration storybook
node_modules/@storybook/theming/dist/cjs doesn’t include any files. Does anyone have a similar issue?
@techhysahil i believe that hook is available in react-router but not react-router-dom. if you’re importing from react-router in your project without declaring as a dependency you’re implicitly reliant on whatever version your dependencies bring in (in this case storybook upped to v6). if you haven’t already try adding it per my comment above.
i am also facing the same problem even though react-router-dom package in my package.json point to 5.xx version. i was using
useHistoryhook from react-router v-5. But now as the react-router got updated to 6.xx … now it’s does not have above hook support. It purposes a new method but i will have to change it at lot of places to fix my build.Do you have a dependency on
react-router@5in your app? you shouldn’t be relying on storybook’s version ofreact-routerin your app, right? or am i misunderstanding?