Storybook: React as peer dependency

Created on 31 Mar 2020  路  4Comments  路  Source: storybookjs/storybook

Is your feature request related to a problem? Please describe.
While using yarn workspaces, packages are hoisted. If my project is using React, then there's conflicts between versions and I get this classic error reported here

Describe the solution you'd like
A solution could be to set React as peer dependency and write in the doc to install React when installing storybook.

Are you able to assist bring the feature to reality?
Yes

Additional context
My issue is a special case:
The error doesn't come when I'm using storybook but when I'm having a lerna, with 2 packages : an UI-kit with Storybook and a React Native application (which I have to nohoist because of Metro broken symlinks). React is hoisted to the root because it's in storybook deps.

dependencies has workaround

Most helpful comment

Alright! I'm going to investigate, I close this issue for now and I'll add more informations later if I find a good solution. Thanks for the fast reply!

All 4 comments

I don't think this is going to happen. Storybook depends on a specific version of React--it's up to you to make sure your dependencies get hoisted properly.

Alright! I'm going to investigate, I close this issue for now and I'll add more informations later if I find a good solution. Thanks for the fast reply!

Storybook for react is 2 react applications running in parallel; which communicate with each other via a postmessage channel.

The manager application uses React specified from our dependencies.
(this is the outer shell)

The preview application uses React specified in your package.json.
(this is where your components are rendered)

The manager applications requires a modern version of React.

If the 2 versions are similar enough, yarn/npm will hoist them to the root and they'll be the exact same version/module.

Worst case I think you can probably depend on the version of React you want hoisted in the root. Though there are probably better ways to get Yarn to do what you want.

Was this page helpful?
0 / 5 - 0 ratings