Skip to content
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

Storybook uses custom babel.config.js file when it shouldn't? Upgraded from 5 to 6 #12967

Closed
ghost opened this issue Oct 31, 2020 · 6 comments
Closed

Comments

@ghost
Copy link

ghost commented Oct 31, 2020

Not sure if this is a bug or as intended.

I was using Storybook 5 and recently upgraded to 6 ("@storybook/react": "^6.0.27") which includes TypeScript support out-the-box (I'm using TypeScript).
However now Storybook is throwing some babel-loader errors, for example:

WARNING in ./src/Paper/Paper.stories.tsx 18:2
Module parse failed: Unexpected token (18:2)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
You may need an additional loader to handle the result of these loaders.
|
| export const Default = () => (
>   <ThemeProvider theme={createTheme()}>
|     <StyledPaper>
|       <Typography>Default paper with dimensions</Typography>
 @ \.)(?=.)[^\\\/]*?\.stories\.tsx)$ (./src sync ^\.(?:(?:^|[\\\/]|(?:(?:(?!(?:^|[\\\/])\.).)*?)[\\\/])(?!\.)(?=.)[^\\\/]*?\.stories\.tsx)$) ./Paper/Paper.stories.tsx
 @ ./.storybook/generated-stories-entry.js
 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/storybook-init-framework-entry.js ./.storybook/generated-stories-entry.js (webpack)-hot-middleware/client.js?reload=true&quiet=false&noInfo=undefined

To Reproduce
Have a custom babel.config.js file in the root of your directory and storybook will load that, which for me caused the above issues.

Workaround / Fix
To fix this I updated my config .storybook/main.js with the following:

babel: async options => ({ ...options, babelrc: false })

And changed my babel.config.js file to .babelrc

This is just a temporary fix for myself though - perhaps there is a better solution?

Systems

Tested on both Mac and Windows, same issue.

@andrico1234
Copy link

I'm having this issue too. it looks build-storybook is failing when there's jsx in the preview.js file.

@shilman
Copy link
Member

shilman commented Nov 25, 2020

Do you have a repro repo you can share?

Also, FYI for a better workaround, in addition to babelrc: false there's also configFile: false so you don't need to rename.

@ghost
Copy link
Author

ghost commented Nov 26, 2020

Do you have a repro repo you can share?

Also, FYI for a better workaround, in addition to babelrc: false there's also configFile: false so you don't need to rename.

Yeah sure, I have a public repo where I apply the workaround, haven't touched it since I originally raised the issue: https://github.com/Ed-Ed/elements

@shilman
Copy link
Member

shilman commented Nov 27, 2020

Aha, I think this is the intended behavior. Maybe in earlier versions of Storybook we only supported .babelrc files and then in 6 we also added babel.config.js? At any rate that's the expected behavior now...

@ghost
Copy link
Author

ghost commented Nov 30, 2020

Sounds about right. I'll close this issue then.

@ghost ghost closed this as completed Nov 30, 2020
@asifsaho
Copy link

asifsaho commented Apr 3, 2022

Thanks, @Ed-Ed for opening this topic and @shilman for making your comment. It works and ended my time-killing tries!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants