storybook: Root babel.config.js not loaded
Describe the bug
Storybook does not load any babel.config.js files (in either root or .storybook). It only loads .storybook/.babelrc files.
To Reproduce Steps to reproduce the behavior:
- Create a new storybook app
- Add a root-level
babel.config.jsfile - Run app
- See that config is not loaded
Expected behavior Storybook should be able to load both babel config formats.
Code snippets I believe this is the code responsible: https://github.com/storybooks/storybook/blob/fba0541a2bbbd3b51943b21d3f8d2282e33286d6/lib/core/src/server/utils/load-custom-babel-config.js#L62
System:
- OS: MacOS
- Device: Macbook Pro 2018
- Framework: React
- Version: 5.x
Additional context https://github.com/emotion-js/emotion/issues/1306
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 25
- Comments: 25 (6 by maintainers)
Commits related to this issue
- Handle loading `.storybook/babel.config.js` (#6633) (#6634) Handle loading `.storybook/babel.config.js` (#6633) — committed to storybookjs/storybook by ndelangen 5 years ago
I created an empty
.babelrcin thestorybookconfig directory and it respects my rootbabel.config.jsNope,
babelModeV7: truedidn’t make a differenceHi there, I can also recreate this issue in Storybook v6. Albeit, I solely use babel.config.js files. Likewise, my solution is to create an empty
/.storybook/babel.config.jsfile. Afterwards, runningstart-storybookwill respect/babel.config.jsWould love if we can get this issue patched. It would be great to not have to create an empty
/.storybook/babel.config.jsto get the/babel.config.jsrespected as desirededit: As per this migration note from sb5, this seems intentional. Could we get this project level config back 😸
my specs: os x yarn 2.2.2 (berry) node@v12.16.3 “@storybook/addon-actions”: “^6.0.12”, “@storybook/addon-knobs”: “^6.0.12”, “@storybook/addons”: “^6.0.12”, “@storybook/react”: “^6.0.12”,
@shilman I just tried 5.1.0-rc.0 with a root babel.config.js. I get this:
A
cis indeed the first character of the config.The problem comes from this line:
https://github.com/storybooks/storybook/commit/a08f44e4813ce19f9ff2670d9c1ccb312e94cb22#diff-cbcd9978dcfe6d6dafed0b1a16ee99f1R23
It checks if the entire file starts with
module.exports. But the file might start with a comment, whitespace or some other code.Workaround:
I use
extends. I think it is a good workaround now.But I still wish this bug will be fixed.
@shilman This worked as expected for me (with the option enabled and my storybook babel config removed, storybook is now using my root babel config).
My current solution is by adding
rootModeoptions insidebabel-loaderwebpack configuration. And it is working properly without need to create sub-package.babelrcfile. 🙇♂️StoryBook version: 5.3.6 Reference: https://babeljs.io/docs/en/config-files#webpack
For me .babelrc.js was not working when I was trying to apply it for a yarn workspace subpackage. It was not even working when I tried
babe.config.js. All babel config files (babelrc or babel.config.js) were being compiled when I tried to doconsole.logfrom those files, but none of them were making any effect.I had to finally put it inside
.storybook/webpack.config.jsas mentioned hereThat’s correct according to babel docs: https://babeljs.io/docs/en/config-files#config-format
However, don’t forget about
.babelrc.jsfiles – those are valid too.