create-react-app eslint 问题,因为更高级别的文件夹包含另一个应用程序,其中包含 node_modules

Posted

技术标签:

【中文标题】create-react-app eslint 问题,因为更高级别的文件夹包含另一个应用程序,其中包含 node_modules【英文标题】:create-react-app eslint issue due to higher level folder containing another app with node_modules in it 【发布时间】:2019-05-29 07:04:15 【问题描述】:

我有一个 git 存储库,其中有 2 个项目,一个环回应用程序(命名应用程序)和一个使用 create-react-app 创建的反应应用程序(命名客户端)。 目录结构如下;

├─┬app
│ ├──node_modules
│ ├─┬client
    ├─node_modules

loopback项目(app)使用eslint,在devDependencies中有eslint,client在package.json中没有eslint。

客户端应用程序是使用 create-react-app 创建的,所以当我运行 react-scripts 时,它会在上层目录中找到 eslint,并抱怨它的版本,如果我删除 app\node_modules 一切正常。

那么 react-scripts 如何在上层目录中找到 eslint,有没有办法告诉它不要检查任何其他 node_modules 文件夹,它应该只检查当前文件夹。

react-scripts 告诉我可以将 SKIP_PREFLIGHT_CHECK=true 放在我的 .env 文件中,这样做是否安全,它是在上层文件夹上运行 eslint 3.x,还是运行所需的 5.6。 0 版本安装在 client\node_modules 文件夹中?

我将为这个项目设置一个部署工具链,所以我需要确保它一直都能正常工作。 编辑: 我的 client\package.json 中的配置条目

"eslintConfig": 
    "extends": "react-app",
    "root": true
  ,

EDIT2: 重现问题的步骤: 我的节点版本是:8.11.3

npx loopback-cli app (accept default options when prompted)
cd app
npm i
npx create-react-app client
cd client
npm i
npm run start (you should see the errors after this)

EDIT3: 我最终弹出了反应脚本。

【问题讨论】:

【参考方案1】:

尝试在您的client 文件夹中创建一个.eslintrc 文件,包括以下内容:

.eslintrc


  "extends": "react-app"

或者,这应该可以工作according to the docs:


    "root": true

默认情况下,ESLint 会在所有父文件夹中查找配置文件,直到根目录。如果您希望所有项目都遵循某种约定,这可能很有用,但有时会导致意想不到的结果。要将 ESLint 限制为特定项目,请将 "root": true 放在 package.json 文件的 eslintConfig 字段或项目根级别的 .eslintrc.* 文件中。 ESLint 一旦找到带有“root”的配置,就会停止在父文件夹中查找:true。

【讨论】:

"eslintConfig": "extends": "react-app", "root": true ,我也试过了。 这些错误何时显示?在您的 IDE 内或在客户端内运行 npm run start 时? 显示为构建、测试、运行等反应脚本的输出。 @hazimdikenli 你能提供一个可重现的例子吗?然后我会尝试调试这个 @dschu 这里是example,感谢您的关注

以上是关于create-react-app eslint 问题,因为更高级别的文件夹包含另一个应用程序,其中包含 node_modules的主要内容,如果未能解决你的问题,请参考以下文章

Create-React-App项目外使用它的eslint配置

禁用 create-react-app 提供的 ESLint

Node.js - 在终端中显示 ESLint 错误,如 create-react-app

create-react-app — 如何将 EXTEND_ESLINT 设置为 true?

create-react-app 版本 5 的“eslint-config-react-app”问题

一起使用 create-react-app 和 Sublimelinter ESlint