question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Root .babelrc not being read

See original GitHub issue

Describe the bug Storybook does not seem to respect my .babelrc file at the root of my project. When I copy/paste the .babelrc into my .storybook folder, it works as expected.

To Reproduce Steps to reproduce the behavior:

  1. Create .babelrc file in project root
  2. Run npm run storybook
  3. See output
  4. Copy root level .babelrc into .storybook directory
  5. Run npm run storybook
  6. See that output differs from step 3

Expected behavior I expect storybook to honor my .babelrc file at the project root level.

Screenshots Notice the pink background when .babelrc is in .storybook: image

Notice no pink background and CSS error when .babelrc is not present: image

Code snippets contents of .babelrc:

{
    "presets": [
        "@babel/preset-env",
        [
            "@babel/preset-react",
            {"runtime": "automatic", "importSource": "@emotion/react"}
        ]
    ],
    "plugins": [
        "@emotion",
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-object-rest-spread"
    ]
}

contents of main.js from .storybook:

const path = require('path');
module.exports = {
    "stories": [
    "../src/**/*.stories.mdx",
    "../src/**/*.stories.@(js|jsx|ts|tsx)"
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials"
  ],
  webpackFinal: async (config, { configType }) => {
    console.log(config.module.rules[0].use[0])
    config.module.rules.push({
      test: /\.scss$/,
      use: ['style-loader', 'css-loader', 'sass-loader'],
      include: path.resolve(__dirname, '../'),
    });
    return config;
  },
};


System Environment Info:

System: OS: macOS 10.15.7 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Binaries: Node: 15.5.0 - ~/.nvm/versions/node/v15.5.0/bin/node npm: 7.3.0 - ~/.nvm/versions/node/v15.5.0/bin/npm Browsers: Firefox: 84.0.1 Safari: 14.0.2 npmPackages: @storybook/addon-actions: ^6.2.0-alpha.10 => 6.2.0-alpha.10 @storybook/addon-essentials: ^6.2.0-alpha.10 => 6.2.0-alpha.10 @storybook/addon-links: ^6.2.0-alpha.10 => 6.2.0-alpha.10 @storybook/react: ^6.2.0-alpha.10 => 6.2.0-alpha.10

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
heyheyhellocommented, Aug 20, 2021

I’m trying to do the opposite and cannot for the life of me get Storybook to only use ./storybook/.babelrc.json and ignore the root config. I’ve tried specifying my options directly in main.js with babel: () => ({ ... }) and have used babelrc: false and multiple attempts of babelrcRoots to no avail. It’s stange how difficult it is to tell Babel to use an alternative config… I think I’ll settle for a shell script that deletes/renames the root config to something else. Yikes.

When the situation is better understood it’d be lovely to see https://storybook.js.org/docs/react/configure/babel/ updated with examples

4reactions
armandabriccommented, Jun 30, 2021

I’m facing the same problem. My root babel.config.js is ignored by storybook.

As workaround I have merge my babel configuration with the storybook one:

  babel: async (options) => {
    const babelConfig = require("./../babel.config.js");

    return { ...options, ...babelConfig };
  },

I’m using storybook v6.3.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Config Files - Babel.js
New in Babel 7.x, Babel has a concept of a "root" directory, which defaults to the current working directory. For project-wide configuration, Babel...
Read more >
Webpack babel-loader isn't reading .babelrc - Stack Overflow
I faced similar issue and that's what I found out. Setting up the debug option in .babelrc { "presets": [ ["env", { "targets":...
Read more >
babel-loader - npm
cache/babel-loader or fallback to the default OS temporary file directory if no node_modules folder could be found in any root directory.
Read more >
What is @babel/preset-env and why do I need it? - Jakob Lind
It's not a nice feeling to just type something that you read in a tutorial without really ... Add a file called .babelrc...
Read more >
选项 - Babel 中文文档
json files within the "root" package because otherwise Babel cannot know if a given .babelrc.json is meant to be loaded, or if it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found