Easily share environment variables with Create React App
See original GitHub issueIs your feature request related to a problem? Please describe. React Storybook and Create React App both require a prefix in environment variables. This makes environment switches cumbersome because both prefixes have to be defined and checked.
For example
.env
STORYBOOK_ENDPOINT=/.netlify/functions/api
REACT_APP_ENDPOINT=/.netlify/functions/api
Then later you have to check both the STORYBOOK prefixed and the REACT_APP prefixed endpoints.
Describe the solution you’d like Allow REACT_APP prefixed environment variables - it may be good to make it opt in, because it’s otherwise possible to leak information that people did not intend to be in production storybook builds.
Describe alternatives you’ve considered It’s probably possible to do this manually with webpack overrides, but this seems like a common use case.
Are you able to assist bring the feature to reality? Looks like it would be a one line change, though I’m not sure exactly how we’d make it opt-in. https://github.com/storybooks/storybook/blob/4da246bbe9413510b48d1ab8b9faf4fae4656d92/lib/core/src/server/config/utils.js#L29
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:16 (10 by maintainers)

Top Related StackOverflow Question
Possible regression? I just added Storybook to a new CRA app with:
An environment variable
process.env.REACT_APP_DEBUGis missing when the component renders in Storybook though the environment variable is present when running the CRA dev server.Package.json has:
I do not have this problem with an earlier version of Storybook:
It’s entirely possible that I’ve misconfigured something, looks like Storybook has changed a bit since 5.2.4.
Why it is like this in the first place? Why only allow STORYBOOK variables and not the rest? But then still load a default .env file (https://github.com/storybookjs/storybook/blob/next/lib/core/src/server/config/utils.js#L39).
It seems this filtering could be removed and leave it to the developer.
When this was added there was no discussion about it, just accepted: https://github.com/storybookjs/storybook/pull/1474, It is possible to revisit this decision?