storybook: Error: Plugin/Preset files are not allowed to export objects, only functions
Bug or support request summary
I tried latest Storybook @ 4.0.0-alpha.12 with latest React Scripts (Create React App) @ 2.0.0-next.3e165448 and got the following error:
ERROR in ./.storybook/config.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/xxx/web/node_modules/babel-preset-stage-0/lib/index.js
ERROR in ./.storybook/addons.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/xxx/web/node_modules/babel-preset-stage-0/lib/index.js
The reason I use 2.0.0 of React Scripts is support of mono repository and Lerna.
Content of .storybook/config.js:
import {addDecorator, configure} from '@storybook/react';
import {decorator} from "../src/stories/Wrapper";
addDecorator(decorator);
configure(() => {
var req = require.context('../src', true, /\.story\.js$/);
req.keys().sort((a, b) => a.localeCompare(b)).map(req);
}, module);
Content of .storybook/addons.js:
import '@storybook/addon-actions/register';
import '@storybook/addon-knobs/register';
Please specify which version of Storybook and optionally any affected addons that you’re running
- @storybook/react 4.0.0-alpha.12
- @storybook/addon-something 4.0.0-alpha.12
- react-scripts 2.0.0-next.3e165448
- webpack @ 4.15.1
I guess it’s because 2.0.0 version is using Babel 7: https://github.com/storybooks/storybook/issues/3335
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 16 (4 by maintainers)
create .babelrc inside storybook directory and paste the following in it.
{ "presets": ["module:metro-react-native-babel-preset"], }hope this helps…With current alpha (
4.0.0-alpha.20), Babel 7 should work OK without hacks with webpack config@Hypnosphi I have still this kind of problem on 4.1.2
best solution is found is to add
in package.json
@Hypnosphi I ran into the same issue on 4.1.2 with react native 0.58.4
I created a demo repo (new react native project from scratch): https://github.com/stigi/storybook-issue-3843/tree/master
cc @dusan-dragon
This is what I had to do to get it working correctly. Hope this helps
package.json
The final look of
webpack.config.jsis:This makes sure I use same Babel config as CRA, with all the monorepo packages.
npm install babel-coreshould fix it for now, until #3746 is merged