简体   繁体   English

使用 create-react-app 和 storybook 的依赖树错误

[英]dependency tree error using create-react-app and storybook

TLDR: TLDR:

how can I instruct storybook to use babel-loader v8.1.0 OR force react-scripts to use babel-loader v^8.2.2?如何指示故事书使用 babel-loader v8.1.0 或强制 react-scripts 使用 babel-loader v^8.2.2?

Details细节

I Develop a lib with./example folder which is itself project created with create-react-app.我使用./example 文件夹开发一个库,该文件夹本身就是使用 create-react-app 创建的项目。 I wanted to add storybook in addition to the normal example pages, so I installed storybook.我想在普通示例页面之外添加故事书,所以我安装了故事书。
after installing storybook I can no longer start the example project with yarn start or the story book with yarn storybook .安装 storybook 后,我无法再使用yarn start启动示例项目或使用yarn storybook启动故事书。

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:

  D:\Eliav\projects\git projects\react-xarrows\examples\node_modules\babel-loader (version: 8.2.2)

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.

well I know what the issue but I don't know how to fix it:好吧,我知道问题出在哪里,但我不知道如何解决:

I'm using react-scripts v4.0.3 which for unknown reason requiring exactly babel-loader v8.1.0.我正在使用react-scripts v4.0.3,由于未知原因,它完全需要babel-loader v8.1.0。 i can see this it in yarn.lock:我可以在 yarn.lock 中看到它:

react-scripts@^4.0.1:
  version "4.0.3"
  ...
  dependencies:
    ...
    babel-loader "8.1.0"

and storybook requiring babel-loader v8.2.2 or above:和需要babel-loader v8.2.2 或更高版本的故事书:

"@storybook/builder-webpack4@6.2.9":
  version "6.2.9"
  ...
  dependencies:
    ...
    babel-loader "^8.2.2"

already tried已经尝试过

  • what is written in the error above.上面的错误中写的是什么。
  • hoped that yarn upgrade would upgrade babel-loader from v8.1.0 to v8.2.2 but it does not work because react-scripts require exactly v8.1.0希望yarn upgrade将 babel-loader 从 v8.1.0 升级到 v8.2.2 但它不起作用,因为 react-scripts 需要 v8.1.0

a workaround that worked一种有效的解决方法

Create a.env file in your project directory and include SKIP_PREFLIGHT_CHECK=true in the file.在您的项目目录中创建一个 .env 文件,并在文件中包含 SKIP_PREFLIGHT_CHECK=true。

but I want to avoid it.但我想避免它。 is it possible?可能吗?

2 Links to consider https://github.com/facebook/create-react-app/issues/10123 and https://github.com/storybookjs/storybook/issues/4764#issuecomment-740785850 2 链接考虑https://github.com/facebook/create-react-app/issues/10123https://github.com/storybookjs/storybook/issues/4764#issuecomment-740785850

Seems that most people are installing the package to get it to work even thou it says not to install in manually.似乎大多数人都在安装 package 以使其工作,即使它说不要手动安装。

So try:所以试试:

yarn add babel-loader@8.1.0纱线添加 babel-loader@8.1.0

So for anyone to whom this is still unclear.因此,对于任何对此仍不清楚的人来说。

I used create-react-app to create a new app I added storybook using sb init我使用 create-react-app 创建了一个新应用我使用 sb init 添加了故事书

then they clashed.然后他们发生了冲突。

SOLUTION:解决方案:

yarn add babel-loader@8.1.0纱线添加 babel-loader@8.1.0

After this all will work Fine.在这一切都会正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM