node.js - create-react-app eslint 问题是由于更高级别的文件夹包含另一个带有 node_modules 的应用程序

标签 node.js reactjs npm

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

├─┬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
  },

编辑 2: 重现问题的步骤: 我的 Node 版本是: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)

编辑 3: 我最终弹出了 react 脚本。

最佳答案

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

.eslintrc

{
  "extends": "react-app"
}

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

{
    "root": true
}

By default, ESLint will look for configuration files in all parent folders up to the root directory. This can be useful if you want all of your projects to follow a certain convention, but can sometimes lead to unexpected results. To limit ESLint to a specific project, place "root": true inside the eslintConfig field of the package.json file or in the .eslintrc.* file at your project’s root level. ESLint will stop looking in parent folders once it finds a configuration with "root": true.

关于node.js - create-react-app eslint 问题是由于更高级别的文件夹包含另一个带有 node_modules 的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54009617/

相关文章:

javascript - unhandledRejection 后是否需要重新启动我的应用程序

javascript - 从对象数组构造元素数组?

reactjs - 为什么 Flow 将我的 React 组件报告为 `incompatible with string` ?

javascript - React js 在页面加载时触发提交函数

javascript - 创建 Angular 项目时出错

npm - 有什么方法可以使用不同的配置和 babel 生成多个转译文件吗?

javascript - 如何访问meteor.js中集合的元素?

javascript - Gatsby 中对象内部的 Prop

node.js - 在包安装 Node 上显示许可证

javascript - 我可以将 expressjs 配置为通过 http 提供某些页面,而通过 https 提供其他页面吗?