无法加载在 'package.json » eslint-config-react-app' 中声明的插件 'flowtype':找不到模块 'eslint/use-at-your-own-risk'

Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk'

我用 create-react-app 创建了一个新的 React 项目。

在终端npm start.

立即得到这个错误

Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk'

我该如何解决这个问题?

具体不是这个项目,但我如何才能 create-react-app 正确创建?

发生的事情是,当你 运行 npm start 它可能正在使用 eslint 进行一些检查,根据我的记忆,create-react-app 有一些检查会在你有 eslint 错误时破坏你的构建所以他们的关联是有道理的。

您在此处遇到的错误与 eslint 使用的称为 subpath exports 的节点功能有关,但它的支持取决于库的使用方式。这已被突出显示,例如与 jest 一起使用时会导致问题。

对于 flowtype eslint 插件,this 是导致您出现问题的确切代码行。

您还可以阅读有关 typescript eslint plugin 的类似问题报告。


解决方案和我什至能够理解导致此问题的原因是我昨天在 eslint-plugin-flowtype 的克隆中对此进行了修复(假设原始插件缺少维护)这里 https://github.com/flow-typed/eslint-plugin-ft-flow/pull/23.

我会提出一个关于 create-react-app 的问题,看看他们是否愿意用新的插件替换插件,这样会有更多的维护并解决您遇到的问题。

我在 webstorm 和 react 中遇到了同样的问题。在阅读了其他人的评论后,我的解决方案是使用 Eslint 7.32.0 版,我最初使用的是 6.8,这是导致问题的原因,现在可以使用了。我还了解到不支持版本 8 或更高版本

我只是删除了这个问题:

"eslintConfig": {
  "extends": [
    "react-app",
    "react-app/jest"
  ]
}

在 package.json

我也有同样的问题。所以就我而言,我发现我的节点版本是 v12。所以我知道了 CRA v5.x 应该与 >= node v14 一起使用。 所以我切换到 Node v16.10.0 并解决了它。

DISABLE_ESLINT_PLUGIN=true react-app-rewired start 可以避免这个错误,并且不需要“>= node v14”(即使 node10 也可以工作),因为只有 eslint@8 使用 Module.createRequire,参考文档Upgrade to react-scripts@5 and Add Web Workers support and APP PixelShapeRN commit Add Web Workers support for CRA v5 (and Webpack 5)

我还发现我可以通过将我的节点版本切换到 LTS 版本来解决这个问题。

  • 我在 运行 节点版本 12.13.0
  • 时遇到了这个问题
  • 切换到版本 16.14.2 解决了我的问题。