Skip to content
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

Why does @storybook/addon-docs have babel-loader as a peer dependency? #13183

Closed
kaiyoma opened this issue Nov 19, 2020 · 33 comments
Closed

Why does @storybook/addon-docs have babel-loader as a peer dependency? #13183

kaiyoma opened this issue Nov 19, 2020 · 33 comments

Comments

@kaiyoma
Copy link

kaiyoma commented Nov 19, 2020

Describe the bug
When I install packages, I get this warning:

warning "@storybook/addon-docs@6.1.1" has unmet peer dependency "babel-loader@^8.0.0".

Why should I add babel-loader as a dependency when it already comes with Storybook? Doing so is kind of dangerous because it runs the risk of having mismatched versions in the dependency tree. It seems like this peer dependency is not needed.

To Reproduce
Steps to reproduce the behavior:

  1. Install @storybook/addon-docs with yarn.

Expected behavior
No warnings.

System

Environment Info:

  System:
    OS: Windows 10 10.0.19042
    CPU: (4) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  Binaries:
    Node: 14.15.0 - C:\Program Files\Node.js\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.8 - C:\Program Files\Node.js\npm.CMD
  Browsers:
    Chrome: 86.0.4240.198
    Edge: Spartan (44.19041.423.0), Chromium (86.0.622.69)
@shilman
Copy link
Member

shilman commented Nov 19, 2020

Addon docs uses babel-loader AFAIK. So it should either be a dependency or a peer dependency. We might be able to loosen up the version specifier? Or do you have another proposal?

@kaiyoma
Copy link
Author

kaiyoma commented Nov 19, 2020

Given that any user of this addon will obviously have Storybook installed, they'll already have babel-loader:

$ yarn why babel-loader
yarn why v1.22.5
[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 Reasons this module exists
   - "_project_#@storybook#core" depends on it
   - Hoisted from "_project_#@storybook#core#babel-loader"
info Disk size without dependencies: "72KB"
info Disk size with unique dependencies: "580KB"
info Disk size with transitive dependencies: "4.45MB"
info Number of shared dependencies: 26
Done in 2.24s.

I'm not sure what's gained by the peer dependency. Keeping my babel-loader dependency in sync with whatever is being shipped with Storybook seems like unnecessary and time-consuming maintenance. Isn't it better to avoid the potential of version mismatches in the tree of dependencies?

@prymitive
Copy link

FYI react-scripts package expects a specific version of babel-loader and will fail to run if installed version is not what it wants.
It seems that storybook/core can pull in a newer version (as the dependency there is more relaxed) which breaks CRA:

> react-scripts build


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/lukasz/Work/karma/ui/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/lukasz/Work/karma/ui/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!
npm ls babel-loader
ui@0.0.1 /Users/lukasz/Work/karma/ui
├─┬ @storybook/react@6.1.1
│ └─┬ @storybook/core@6.1.1
│   └── babel-loader@8.2.1
└─┬ react-scripts@3.4.4
  └── babel-loader@8.1.0

@cseas
Copy link

cseas commented Nov 21, 2020

I'm getting the same error with react-scripts as the previous comment.
If storybook is using create-react-app as a preset then wouldn't it make sense it should use the same babel-loader version that CRA uses?

Using a different version will always lead to the above error.

@shilman
Copy link
Member

shilman commented Nov 21, 2020

@cseas Yes, see #4764. @mrmckeb @tooppaaa can one of you please take care of this? it seems to be generating a lot of problems for people... 🙏

@prymitive
Copy link

I see that a similar problem applies to webpack, the difference is that webpack is only peer dependency so you end up with a warning rather than a build failure:

├─┬ @storybook/react@6.1.2
│ ├─┬ @storybook/core@6.1.2
│ │ └── webpack@4.44.2
│ └── UNMET PEER DEPENDENCY webpack@4.44.2
└─┬ react-scripts@3.4.4
  └── webpack@4.42.0

@elie222
Copy link

elie222 commented Nov 24, 2020

I noticed that #4764 has been closed. Not sure if this was supposed to solve this issue?
I'm on Storybook v6.1.5 and am still seeing this issue.

@shilman
Copy link
Member

shilman commented Nov 24, 2020

@elie222 meaning you installed a fresh copy of storybook on a CRA with 6.1.5 and you're seeing the issue?

@elie222
Copy link

elie222 commented Nov 24, 2020

Not a fresh copy.

Using react-scripts 4.0.1 and Storybook 6.1.5 but upgrading an existing project:
https://github.com/FrontWorkDotDev/react-typescript-storybook-starter

@shilman
Copy link
Member

shilman commented Nov 24, 2020

@elie222 The fix here was NOT to install babel stuff at all if we're installing into a CRA app and to directly use the CRA setup instead. So it only applies to new storybook installs generated by the CLI. FWIW I'm not confident about the fix, but this issue seemed like it was breaking a bunch of people and it is worth a try.

It doesn't seem like there's a good solution for existing apps, other than perhaps to delete the dependencies by hand and reinstall. Can you try that?

@elie222
Copy link

elie222 commented Nov 25, 2020

Still no luck.

The output we're getting when running yarn start is below. Basically started from a blank CRA app and still got the error. yarn storybook works fine for us. Leaving as is for now as we don't actually need the CRA part for now but looks like this issue is still open.

yarn run v1.22.5
$ 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/Elie/Documents/Projects/FrontWork/storybook-repos/react-typescript-storybook-starter/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/Elie/Documents/Projects/FrontWork/storybook-repos/react-typescript-storybook-starter/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!

@SaschaDens
Copy link

I've experienced just the same issue with a fresh install of Storybook in a Create-React-App.
In order to continue I've temporary added the following line in package.json which allowed yarn to resolve babel-loader 8.1.0:

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

This doesn't solve it for NPM yet.

@AveryTheDev
Copy link

The above doesn't work for me, even though I am using yarn. Has any progress been made on this issue?

@AveryTheDev
Copy link

Ah nvm, you need to follow with yarn install after adding that section of json to your package.json file per these instructions. I'm posting it here for those who were unfamiliar like me.

https://classic.yarnpkg.com/en/docs/selective-version-resolutions/#toc-how-to-use-it

@FutureKode
Copy link

I'm seeing this issue with npm when upgrading from react-scripts v3 to v4.

@shilman
Copy link
Member

shilman commented Jan 20, 2021

Storybook docs now uses the babel-loader provided by storybook core, so I think this is resolved at some level. I'm not sure what to do with the peer dependency tho.. @merceyz @gaetanmaisse thoughts?

@gaetanmaisse
Copy link
Member

I think we can clean everything on the addon-docs side, I mean remove the peerDep and update the READMEs, do you agree @merceyz?

@merceyz
Copy link
Contributor

merceyz commented Jan 20, 2021

Yeah, makes sense to clean that up, should include @babel/core in that as it's both a dependency and a peer dependency

@gaetanmaisse
Copy link
Member

Ok, I will do it later today, thanks a lot for the feedback @merceyz :)

@gaetanmaisse gaetanmaisse self-assigned this Jan 21, 2021
@maxsilvauk
Copy link

Is there a solution for npm for this just experienced this with my project?

@Duncan-Alexander-Coutts

Still seeing this issue too, all with latest versions

@jgresham
Copy link

Ok, I will do it later today, thanks a lot for the feedback @merceyz :)

bump :)

@shilman
Copy link
Member

shilman commented Apr 23, 2021

Yay!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-alpha.14 containing PR #14689 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Apr 23, 2021
@jgresham
Copy link

thank you @shilman!

@NTag
Copy link

NTag commented Apr 30, 2021

It's better, thank you 🙏 , but I think there is sill an issue with @storybook/addon-docs:

CleanShot 2021-04-30 at 10 32 15@2x

@merceyz
Copy link
Contributor

merceyz commented May 5, 2021

but I think there is sill an issue with @storybook/addon-docs:

@NTag Please elaborate as that output looks fine

@NTag
Copy link

NTag commented May 5, 2021

babel-loader@8.2.2 is still installed (by @storybook/builder-webpack4 which is used by @storybook/addon-docs), whereas react-scripts wants babel-loader@8.1.1, so react-scripts still doesn't want to start.

@merceyz
Copy link
Contributor

merceyz commented May 5, 2021

That's not an issue with Storybook, see #14811 (comment). Disable the preflight check and it should work

@NTag
Copy link

NTag commented May 5, 2021

Ok, that makes sense 👍 . Thanks!

@Nautman
Copy link

Nautman commented Aug 17, 2021

So, is the "right" solution to disable the preflight check? :)

@shilman
Copy link
Member

shilman commented Aug 18, 2021

yes @Nautman

@gaetanmaisse gaetanmaisse removed their assignment Aug 25, 2021
@dudulasry
Copy link

Is this problem going to be solved on CRA side? Does anyone know?

@shilman
Copy link
Member

shilman commented Aug 31, 2021

I've heard from a CRA team member that they are planning to relax that check in CRA, but I don't know whether that's still happening since I heard it awhile ago.

yisu-kim added a commit to yisu-kim/storybook-exercise that referenced this issue Nov 2, 2021
seaerchin added a commit to isomerpages/isomercms-frontend that referenced this issue Feb 18, 2022
storybook has a conflict with cra due to versioning issues on babel loader and a faulty check on the
cra side (see: storybookjs/storybook#13183 and
facebook/create-react-app#10123 (comment)). this required either some hackery on the command side (by disabling preflight checks) or upgrading react-scripts to 5.0. as react scripts is not a direct dependency at runtime when serving our application, i opted for this approach.

another issue that cropped up was postcss requiring version 8 due to transistive dependencies (design system -> chakra -> tailwind -> postcss). this was fixed by installing a direct dependency on postcss @ 8, which was the approach mentioned here: postcss/postcss-import#435. A dev mentioned that the API between 7/8 did not differ much and the release notes for 8 (https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users) also mentioned that there are no significant differences for end users, so this should be safe.

tl;dr: build issues are fixed by upgrading dependencies.

if you ever read this message, or any of the previous long commit messages, please drop me a :ultrafastparrot: thx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests