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.

Required Babel 7 error, even with babel 7 installed

See original GitHub issue

If you are reporting a bug or requesting support, start here:

Support request summary

I’ve installed storybook with getstorybook in my create-react-app app, and when I run yarn run storybook, I get the following error:

Module build failed: Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.

Sure enough, If I inspect the trace, there’s a call to babel-core instead of @babel/core.

at throwVersionError (/path/to/app/node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
    at Object.assertVersion (/path/to/app/node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
    at _default (/path/to/app/node_modules/@babel/preset-env/lib/index.js:150:7)
    at /path/to/app/node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
    at /path/to/app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:317:46
    at Array.map (<anonymous>)
    at OptionManager.resolvePresets (/path/to/app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/path/to/app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/path/to/app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/path/to/app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/path/to/app/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/path/to/app/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at Pipeline.transform (/path/to/app/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transpile (/path/to/app/node_modules/babel-loader/lib/index.js:50:20)
    at /path/to/app/node_modules/babel-loader/lib/fs-cache.js:118:18
    at ReadFileContext.callback (/path/to/app/node_modules/babel-loader/lib/fs-cache.js:31:2

I’ve deleted node_modules, yarn.lock, reinstalled multiple times, same issue. I’ve even tried downgrading babel to 6.x, but I don’t know how to make storybook use babel 6.x.

How can I fix this?

Please specify which version of Storybook and optionally any affected addons that you’re running

   "@babel/core": "^7.0.0-beta.53",
    "@babel/plugin-proposal-function-bind": "^7.0.0-beta.53",
    "@babel/preset-env": "^7.0.0-beta.53",
    "@babel/preset-stage-2": "^7.0.0-beta.53",
    "@babel/runtime": "^7.0.0-beta.53",
    "@storybook/addon-actions": "^3.4.8",
    "@storybook/addon-links": "^3.4.8",
    "@storybook/addons": "^3.4.8",
    "@storybook/react": "^3.4.8",

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bmcalliscommented, Jul 14, 2018

The issue here is that the webpack sonfig that storybook uses is using the babel-loader for version 6. But it’s still using your babelrc which has plugins for babel 7. To work around the issue I pushed a rule onto their config specifying the babel-loader that I’m actually using, which is babel 7.

const { resolve } = require('path');
const babelrc = require('../.babelrc');

module.exports = storybookBaseConfig => {
  storybookBaseConfig.module.rules.push(
    {
      test: /\.(js|jsx)$/,
      use: [
        {
          loader: resolve(__dirname, '../', 'node_modules', 'babel-loader'),
          options: {
            cacheDirectory: true,
            ...babelrc,
          },
        },
      ],
      exclude: /node_modules/,
    }
  );

  return storybookBaseConfig;
};

Webpack will then use the babel 7 loader first, but it’ll still run the code through the babel 6 loader as well.

1reaction
alixebcommented, Aug 3, 2018

with "babel-core": "^7.0.0-bridge.0"

ERROR in ./.storybook/config.js
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/xxx/node_modules/babel-preset-stage-0/lib/index.js
    at createDescriptor (/Users/xxx/node_modules/@babel/core/lib/config/config-descriptors.js:179:11)
// storybook/config.js

import { configure } from '@storybook/react'

const req = require.context('../src/components', true, /\.stories\.js$/)

function loadStories() {
  req.keys().forEach((filename) => req(filename))
}

configure(loadStories, module);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Required Babel 7 error, even with babel 7 installed #3883
The issue here is that the webpack sonfig that storybook uses is using the babel-loader for version 6. But it's still using your...
Read more >
Error after upgrading to Babel 7: Requires Babel "^7.0.0-0 ...
When you run your grunt file it is looking for babel-register. However, for babel 7.0.0 and higher, you need it to look for...
Read more >
Upgrade to Babel 7
This just means Babel itself won't run on older versions of Node. It can still output code that runs on old Node versions....
Read more >
babel-loader - webpack
Note: Issues with the output should be reported on the Babel Issues tracker. Install. webpack 4.x | babel-loader 8.x | babel 7.x. npm ......
Read more >
Babel 7: Configuration, Preset, and Plugin Usage
To use Babel we need Node.js installed. We strongly recommend using the latest version (pair) available. This article used version 8.9.3.
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