简体   繁体   English

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

[英]create-react-app eslint issue due to higher level folder containing another app with node_modules in it

I have a git repository which has 2 projects in it, a loopback app (named app), and a react app created with create-react-app (named client). 我有一个git存储库,里面有2个项目,一个环回应用程序(名为app),以及一个用create-react-app(命名客户端)创建的react应用程序。 And the directory structure is as follows; 目录结构如下;

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

the loopback project (app) uses eslint, has eslint in devDependencies, client does not have eslint in package.json. loopback项目(app)使用eslint,在devDependencies中有eslint,客户端在package.json中没有eslint。

Client app is created with create-react-app, so when I run react-scripts, it finds eslint in the upper directory, and complains about its version, if I delete the app\\node_modules everything works fine. 客户端应用程序是使用create-react-app创建的,所以当我运行react-scripts时,它会在上层目录中找到eslint,并抱怨它的版本,如果我删除了app \\ node_modules,一切正常。

So how does react-scripts find the eslint in upper directory, is there a way of telling it not to check any other node_modules folder, it should only check in the current folder. 那么react-scripts如何在上层目录中找到eslint,有没有办法告诉它不要检查任何其他node_modules文件夹,它应该只检查当前文件夹。

react-scripts tells me that I can put SKIP_PREFLIGHT_CHECK=true in my .env file, is it safe to do this, does it run the eslint 3.x on the upper level folder, or does it run the required 5.6.0 version installed in client\\node_modules folder? react-scripts告诉我,我可以在我的.env文件中放入SKIP_PREFLIGHT_CHECK = true,这样做是否安全,是否在上层文件夹中运行eslint 3.x,或者是否运行了安装所需的5.6.0版本在client \\ node_modules文件夹中?

I will setup a deployment toolchain for this project so I need make sure that it works fine all the time. 我将为此项目设置部署工具链,因此我需要确保它始终正常工作。 EDIT: The config entry in my client\\package.json 编辑:我的client \\ package.json中的配置条目

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

EDIT2: Steps to reproduce problems: my node version is: 8.11.3 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: I ended up ejecting react-scripts. 编辑3:我最终弹出反应脚本。

Try creating a .eslintrc file in your client folder, include the following content: 尝试在client文件夹中创建.eslintrc文件,包括以下内容:

.eslintrc .eslintrc

{
  "extends": "react-app"
}

Alternatively, this should work according to the docs : 或者,这应该根据文档工作

{
    "root": true
}

By default, ESLint will look for configuration files in all parent folders up to the root directory. 默认情况下,ESLint将在根目录下的所有父文件夹中查找配置文件。 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限制为特定项目,请将“root”:true放在package.json文件的eslintConfig字段内或项目根级别的.eslintrc。*文件中。 ESLint will stop looking in parent folders once it finds a configuration with "root": true. 一旦找到具有“root”的配置,ESLint将停止查找父文件夹:true。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未复制将 create-react-app 推送到 github node_modules 文件夹 - Pushing create-react-app to github node_modules folder has not been copied 通过运行npm install create-react-app创建的node_modules文件夹有什么用? - What for is the node_modules folder that is created by running npm install create-react-app for? npx create-react-app my-app 创建后删除已安装的 node_modules 包? - npx create-react-app my-app deleting installed node_modules package after creating? 有没有办法复制 node_modules 而不是每次都为 create-react-app 安装它们? - Is there a way to copy node_modules instead of installing them for create-react-app every time? 我可以在 create-react-app 中使用自定义 node_modules 路径吗 - Can I use a custom node_modules path with create-react-app 为什么在使用“npx create-react-app”命令创建项目时,除了“node_modules”和“package.json”之外没有任何文件和文件夹? - Why there isn't any file and folder except 'node_modules' and 'package.json' anymore when creating a project with 'npx create-react-app' command? Create-React-App需要Node 4.0或更高版本 - Create-React-App requires Node 4.0 or higher Create-React-App需要Node 4.0或更高版本-在Windows上 - Create-React-App requires Node 4.0 or higher - on Windows Eslint 不忽略 node_modules 文件夹 - Eslint not ignoring node_modules folder (Create-React-App)找不到模块:您试图导入项目之外的 /node_modules/console-browserify/index.js - (Create-React-App) Module not found: You attempted to import /node_modules/console-browserify/index.js which falls outside of the project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM