无法 npm 使用 eslint 依赖项启动我的 React 项目

Can't npm start my React project with eslint dependencies

我在我的 React 项目中安装了 eslint 来修复所有的 eslint 错误。我修复了所有错误,但是,我无法 npm start 该项目。当我这样做时,我得到了这个错误,以及一些卸载所有 eslint 依赖项的步骤。我想 运行 具有 eslint 依赖项的项目。

请告诉我该怎么做?

错误信息:

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:

"eslint": "^7.11.0"

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

Create React 应用程序已经与 eslint 捆绑在一起,通过将其安装在项目依赖项中,您实际上是在尝试加载冲突的版本,您不应该在自己的 package.json 中需要 eslint。

然而

如果您想覆盖 eslint 并开始自定义您的 React 安装,我们非常欢迎您弹出 (npm run eject),但请记住,弹出您的应用程序意味着您将需要继续维护依赖项.

您可以在此处阅读有关弹出的更多信息 - https://create-react-app.dev/docs/available-scripts/

我的猜测是您安装了 eslint@v8 并且由于 create-react-app 尚不支持它 (reference) 它会导致此错误。

降级到 eslint v7 应该可以解决这个问题。