【问题标题】:dependency tree error using create-react-app and storybook使用 create-react-app 和 storybook 的依赖树错误
【发布时间】:2021-05-10 23:03:07
【问题描述】:

TLDR:

如何指示 storybook 使用 babel-loader v8.1.0 或强制 react-scripts 使用 babel-loader v^8.2.2?

详情

我使用 ./example 文件夹开发一个库,该文件夹本身就是使用 create-react-app 创建的项目。我想在普通示例页面之外添加故事书,所以我安装了故事书。
安装故事书后,我无法再使用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.

我知道是什么问题,但我不知道如何解决它:

我正在使用react-scripts v4.0.3,由于未知原因,它需要精确babel-loader v8.1.0。我可以在 yarn.lock 中看到它:

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

以及需要babel-loader v8.2.2 或更高版本的故事书:

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

已经尝试过

  • 上面的错误中写的是什么。
  • 希望yarn upgrade 将 babel-loader 从 v8.1.0 升级到 v8.2.2,但它不起作用,因为 react-scripts 需要 v8.1.0

一种有效的解决方法

在您的项目目录中创建一个 .env 文件,并在文件中包含 SKIP_PREFLIGHT_CHECK=true。

但我想避免它。有可能吗?

【问题讨论】:

    标签: reactjs dependency-management babel-loader


    【解决方案1】:

    所以对于那些还不清楚的人来说。

    • 我使用create-react-app 创建了一个新应用
    • 我使用npx sb init 添加了故事书

    然后他们发生了冲突。

    解决方案:

    yarn add babel-loader@8.1.0

    更新:

    您经常看到的错误是 CRA (create-react-app) 依赖于特定的依赖项(例如 webpackbabel)。

    您还可以根据错误消息指定这些依赖项必须解析到的版本

    这可以使用package.json 中的resolutions 字段来完成,例如:

        "resolutions": {
            "babel-loader": "8.1.0",
            "webpack": "4.x.x",
        }
    

    之后一切都会好起来的。

    【讨论】:

    • 决议拯救了我的一天!
    【解决方案2】:

    要考虑的2个链接https://github.com/facebook/create-react-app/issues/10123https://github.com/storybookjs/storybook/issues/4764#issuecomment-740785850

    似乎大多数人都在安装软件包以使其正常工作,即使它说不要手动安装。

    那就试试吧:

    纱线添加 babel-loader@8.1.0

    【讨论】:

    • 请解释你的答案,而不是仅仅发布链接。
    • 您的故事书评论链接基本上是说预检检查默认应该是假的,并且创建反应应用程序不应该以任何方式检查这个
    猜你喜欢
    • 2022-01-19
    • 2022-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 2020-02-17
    相关资源
    最近更新 更多