-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Root babel.config.js not loaded #6633
Comments
Handle loading `.storybook/babel.config.js` (#6633)
Boo-yah!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-rc.0 containing PR #6634 that references this issue. Upgrade today to try it out! Because it's a pre-release you can find it on the Closing this issue. Please re-open if you think there's still more to do. |
@shilman I just tried 5.1.0-rc.0 with a root babel.config.js. I get this:
A const presetEnvOptions = {
useBuiltIns: "usage",
// To see which polyfills are used in which files:
// debug: true,
};
const common = {
presets: [["next/babel", { "preset-env": presetEnvOptions }]],
plugins: ["lodash"],
};
module.exports = {
env: {
development: common,
production: common,
// Jest:
test: {
presets: [["next/babel", { "preset-env": { modules: "commonjs" } }]],
},
},
}; The problem comes from this line: a08f44e#diff-cbcd9978dcfe6d6dafed0b1a16ee99f1R23 It checks if the entire file starts with Workaround: module.exports; // workaround
const presetEnvOptions = {
useBuiltIns: "usage",
// To see which polyfills are used in which files:
// debug: true,
};
const common = {
presets: [["next/babel", { "preset-env": presetEnvOptions }]],
plugins: ["lodash"],
};
module.exports = {
env: {
development: common,
production: common,
// Jest:
test: {
presets: [["next/babel", { "preset-env": { modules: "commonjs" } }]],
},
},
}; |
Thank you for this very detailed feedback @lydell ! Perhaps instead of trying to detect what type of file it is, we just try-catch to load it with the 2 methods? |
Isn’t .babelrc always JSON5, and babel.config.js always JS? If so, could
|
That's correct according to babel docs: https://babeljs.io/docs/en/config-files#config-format However, don't forget about |
Is the fix of this issue rollback after 5.1.10? |
Getting the same problem on 5.2.5. Storybook either won't load my .babelrc in the project root, or it doesn't like the 'env' options in it (e.g. production or development settings). When I duplicate the .babelrc file to my .storybook folder and remove the env stuff it works. I don't want 2 babelrc files though! |
This issue is closed, so folks may not see the above. Please make a new issue referencing this one as a regression. (And if it's a regression, it's helpful if you can point out the version to which users need to downgrade in order to have the correct behavior.) |
Automention: Hey @igor-dv, you've been tagged! Can you give a hand here? |
I use {
"extends": "/path/to/your/project/babel.config.js"
} But I still wish this bug will be fixed. |
@vipcxj That doesn't work for me. Only workaround is to change the root |
I created an empty |
For me .babelrc.js was not working when I was trying to apply it for a yarn workspace subpackage. I had to finally put it inside |
My current solution is by adding StoryBook version: 5.3.6 // packages/ui/.storybook/main.js
module.exports = {
stories: ['../src/**/*.stories.tsx'],
webpackFinal: async config => {
const newConfig = {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
rootMode: 'upward'
}
},
require.resolve('react-docgen-typescript-loader')
],
include: path.resolve(__dirname, '../src')
}
]
},
resolve: {
...config.resolve,
extensions: [...(config.resolve.extensions || []), '.ts', '.tsx']
}
};
return newConfig;
}
}; |
We can do a breaking change in 6.0.0 and improve this behaviour. @jeffryang24 @ashoksudani @jono-allen @lydell Would you be interested in taking this on? |
Sorry, I’m not interested but thanks for asking! |
Sorry, I actually want to help but currently I still busy with my company's task. My current idea is just using |
Would this work if the root babel config is in a sibling directory? Example:
|
Looks like with 5.2.6 this works:
|
Hi there, I can also recreate this issue in Storybook v6. Albeit, I solely use babel.config.js files. Would love if we can get this issue patched. It would be great to not have to create an empty edit: As per this migration note from sb5, this seems intentional. Could we get this project level config back 😸 my specs: |
We've introduced a new babel mode in 6.4, documented here: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#babel-mode-v7 If anybody can see whether this resolves the issue for them, we'd really appreciate it. To upgrade:
|
@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). |
@shilman is there anything left to do here? |
Nope, |
Btw I'm using a babel.config.js file in my root folder, not .babelrc |
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:
babel.config.js
fileExpected 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:
Additional context
emotion-js/emotion#1306
The text was updated successfully, but these errors were encountered: