storybook: babel-loader devDependency causes error in Create-React-App

Describe the bug Installing Storybook in a Create-React-App project causes the following error, preventing the app from starting in development:

$ react-scripts start

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "babel-loader": "8.1.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:

  /Users/alanrussell/Documents/playground/sb-sc-bug-repro/node_modules/babel-loader (version: 8.2.1)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /Users/alanrussell/Documents/playground/sb-sc-bug-repro/node_modules/babel-loader is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls babel-loader in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed babel-loader.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Following the steps listed fixes the problem.

To Reproduce

Minimal repro here: https://github.com/ajrussellaudio/sb-sc-bug-repro (also includes styled-components)

  1. Create a new React app with Create-React-App (I used yarn and the TypeScript template): yarn create react-app my-app --template typescript
  2. Install Storybook: npx sb init
  3. Start Storybook: yarn storybook (works fine)
  4. Start the React app: yarn start (throws error above)

Expected behavior sb init should work with the dependencies of the project

System


  System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 15.1.0 - ~/.nvm/versions/node/v15.1.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.0.8 - ~/.nvm/versions/node/v15.1.0/bin/npm
  Browsers:
    Chrome: 86.0.4240.193
    Firefox: 82.0.3
    Safari: 14.0
  npmPackages:
    @storybook/addon-actions: ^6.0.28 => 6.0.28
    @storybook/addon-essentials: ^6.0.28 => 6.0.28
    @storybook/addon-links: ^6.0.28 => 6.0.28
    @storybook/node-logger: ^6.0.28 => 6.0.28
    @storybook/preset-create-react-app: ^3.1.5 => 3.1.5
    @storybook/react: ^6.0.28 => 6.0.28

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Hello @ajrussellaudio, thanks for your work.

Unfortunately, it’s still not working in v6.1.9; if I set up a new project with

npx create-react-app test-app
cd test-app
npx sb@next init
yarn run start

…it still complains about babel-loader@8.2.2 conflicting with react-script’s 8.1.0.

✎  $ yarn why babel-loader
yarn why v1.22.10
[1/4] πŸ€”  Why do we have the module "babel-loader"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] πŸ”  Finding dependency...
[4/4] 🚑  Calculating file sizes...
=> Found "babel-loader@8.2.2"
info Has been hoisted to "babel-loader"
info Reasons this module exists
   - Specified in "devDependencies"
   - Hoisted from "@storybook#react#@storybook#core#babel-loader"
info Disk size without dependencies: "312KB"
info Disk size with unique dependencies: "796KB"
info Disk size with transitive dependencies: "3.68MB"
info Number of shared dependencies: 23
=> Found "react-scripts#babel-loader@8.1.0"
info This module exists because "react-scripts" depends on it.
info Disk size without dependencies: "300KB"
info Disk size with unique dependencies: "700KB"
info Disk size with transitive dependencies: "3.71MB"
info Number of shared dependencies: 25
✨  Done in 0.81s.

in the meantime you can install babel-loader locally fixed to version 8.1.0

(package.json)

    "babel-loader": "8.1.0",

the error went away for me after doing that

Hello… this is still happening. I’m on SB 6.2.1 and react-scripts@4.0.3… Storybook is forcing a newer version of babel-loader

winter-web-app@0.1.0 /Users/jseidel/ppg/hall/winter-spa
β”œβ”€β”¬ @storybook/addon-essentials@6.2.1
β”‚ └─┬ @storybook/addon-docs@6.2.1
β”‚   └─┬ @storybook/builder-webpack4@6.2.1
β”‚     └── babel-loader@8.2.2  deduped
β”œβ”€β”¬ @storybook/react@6.2.1
β”‚ β”œβ”€β”¬ @storybook/core@6.2.1
β”‚ β”‚ └─┬ @storybook/core-server@6.2.1
β”‚ β”‚   └── babel-loader@8.2.2  deduped
β”‚ └─┬ @storybook/core-common@6.2.1
β”‚   └── babel-loader@8.2.2  deduped
└── babel-loader@8.2.2

@ChristianIvicevic Nobody ist installing babel-loader it explicitly. What are you talking about? come back to the real world.

The title of this issue should be β€œstorybook breaks CRA setup!” and it should be opened!

Hello, this is also happening to me after upgrading to Storybook 6.1.2.

Problem: @storybook/core adds babel-loader@8.2.1 as a devDependency. This version clashes with CRA2’s expected version, which is 8.1.0.

Easy way to reproduce:

npx create-react-app test-app
cd test-app
npx sb init
yarn start

✎  $ yarn start
yarn run v1.22.10
$ react-scripts start

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "babel-loader": "8.1.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:

  /Users/marco/test/test-sb-init/node_modules/babel-loader (version: 8.2.1)

Manually installing incompatible versions is known to cause hard-to-debug issues.

More proof:

✎  $ yarn why babel-loader
yarn why v1.22.10
[1/4] πŸ€”  Why do we have the module "babel-loader"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] πŸ”  Finding dependency...
[4/4] 🚑  Calculating file sizes...
=> Found "babel-loader@8.2.1"
info Has been hoisted to "babel-loader"
info Reasons this module exists
   - Specified in "devDependencies"
   - Hoisted from "@storybook#react#@storybook#core#babel-loader"
info Disk size without dependencies: "324KB"
info Disk size with unique dependencies: "824KB"
info Disk size with transitive dependencies: "3.7MB"
info Number of shared dependencies: 24
=> Found "react-scripts#babel-loader@8.1.0"
info This module exists because "react-scripts" depends on it.

in the meantime you can install babel-loader locally fixed to version 8.1.0

(package.json)

    "babel-loader": "8.1.0",

the error went away for me after doing that

Is this recommended? The error message provided (see OP) specifically says

Don’t try to install it manually

@mrmckeb thanks for the reply. Adding the babel-loader dependency is exactly what the sb init step is doing. It’s not an explicit dependency of the app before that point, but is a sub-dependency of react-scripts.

➜ yarn list --pattern babel-loader
yarn list v1.22.10
β”œβ”€ @storybook/core@6.0.28
β”‚  └─ babel-loader@8.2.1
└─ babel-loader@8.1.0
➜ yarn why babel-loader
yarn why v1.22.10
[1/4] πŸ€”  Why do we have the module "babel-loader"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] πŸ”  Finding dependency...
[4/4] 🚑  Calculating file sizes...
=> Found "babel-loader@8.1.0"
info Reasons this module exists
   - "react-scripts" depends on it
   - Hoisted from "react-scripts#babel-loader"
info Disk size without dependencies: "300KB"
info Disk size with unique dependencies: "664KB"
info Disk size with transitive dependencies: "3.58MB"
info Number of shared dependencies: 25
=> Found "@storybook/core#babel-loader@8.2.1"
info This module exists because "@storybook#react#@storybook#core" depends on it.
info Disk size without dependencies: "80KB"
info Disk size with unique dependencies: "448KB"
info Disk size with transitive dependencies: "3.34MB"
info Number of shared dependencies: 24

I’m getting this with react-scripts@3.4.4 and storybook@6.1.16

$ npm ls babel-loader

web-portal@0.1.0 /home/jenkins/workspace/XXX_PR-57
β”œβ”€β”¬ @storybook/addon-essentials@6.1.16
β”‚ β”œβ”€β”¬ @storybook/addon-docs@6.1.16
β”‚ β”‚ └── babel-loader@8.2.2 deduped
β”‚ └── babel-loader@8.2.2
β”œβ”€β”¬ @storybook/react@6.1.16
β”‚ └─┬ @storybook/core@6.1.16
β”‚   └── babel-loader@8.2.2 deduped
└─┬ react-scripts@3.4.4
  └── babel-loader@8.1.0

In my package.json I’ve got:

"resolutions": {
    "babel-loader": "8.1.0"
  }

I’m stuck in this issue right now… CRA + TS…

ERR! Error: Cannot find module β€˜babel-loader’

If I install the babel-loader my React App brokes

Any fix? Any help?

The error message pretty much says it all - either you don’t install babel-loader explicitly or you pin it explicitly to v8.1.0. For compatibility reasons it looks more reasonable to not install it explicitly and always use the one that comes with CRA, since you will have an easier time updating it.

This seems to have been a problem with Storybook v6.1.2, and fixed in v6.1.4. Run npx sb@next upgrade and the problem should go away.

Unfortunately, that didn’t change anything. Trying both npx sb@next upgrade and a fresh install with npx sb@next init both resolve in the same issue, babel-loader 8.2.2 is bundled by storybook.

closing as dupe to #4764