-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRA .env and NODE_PATH #1642
Comments
My problem came from assuming that because CRA reads and operates on an Using default webpack setup based on "Create React App". That assumption is wrong: the export NODE_PATH=src && yarn storybook |
@gihrig Why do you close it? It is real bug. I have same error. |
@Lehakos did the solution above not work for you? You could also set that variable more permanently and forget about it. I'm not sure CRA failing to share its The dotenv project should work to load CRA's |
@Lehakos CRA ( #528 (from #468) provides support for Storybook to read an OS environment var If you want Storybook to read environment vars from an |
Thanks @gihrig. Does anyone have an example to implement this? So far I've tried the following steps, but I can't get my absolute path to work:
And just in case, I've even added a I still cannot get my absolute paths to work. Would greatly appreciate any help! |
@pauldcollins Apparently, Storybook only reads from the OS environment, and CRA does not set OS environment vars from it's .env file. Did you try export NODE_PATH=src && yarn storybook If that works, The dotenv project should work to load CRA's .env contents into the environment, I haven't tried this though.
I do not have a trailing /, e.g. |
Thanks for your quick reply @gihrig I tried removing the slash in the .env file, but it didn't work. Where would I put this line of code? In the .env file or somewhere else?
Thanks again |
Paste that code into the terminal. That should start Storybook with |
That's working now, great stuff! Thanks for your help @gihrig |
.env should work out of the box. |
Does current Storybook/react support NODE_PATH? - Yes it does. See next entry below.
I see this was implemented in #528, That was merged nearly a year ago, using webpack 1? It's not working for me with current Storybook. The specified NODE_PATH works for CRA and its provided Jest, but storybook complains:
Error: Can't resolve 'components/...'
See demo repo here
git clone https://github.com/gihrig/storybook-node-path.git && cd storybook-node-path
yarn
yarn test
- CRA Jest all tests passyarn start
- CRA demo app works as expectedyarn storybook
- Error:Step to reproduce:
create-react-app storybook-path-test
getstorybook
./.env
containingNODE_PATH=src
H2
andHeader
components in./src/components/
, including tests../App.js
./stories.index.js
to include new components.OS X: 10.11.6
node: 8.2.1
CRA: 1.3.3
Storybook/react: 3.2.3
The text was updated successfully, but these errors were encountered: