Skip to content

Allow patch level differences in preflight check #5247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
togakangaroo opened this issue Oct 2, 2018 · 47 comments
Open

Allow patch level differences in preflight check #5247

togakangaroo opened this issue Oct 2, 2018 · 47 comments

Comments

@togakangaroo
Copy link

Is this a bug report?

Yes, I am getting an eslint preflight check error hen I don't think I should be.

Did you try recovering your dependencies?

Yes, I've tried deleting the package-lock and rebuilt some stuff, but this issue seems pretty clearcut

Which terms did you search for in User Guide?

I searched for eslint there and in the issues but this is for the new release and I dont' think thats updated yet

Environment

(paste the output of the command here)

Steps to Reproduce

To reproduce

create-react-app craeslint
cd craeslint
npm install [email protected]

I get the following. I don't think this is correct - a difference in patch version shouldn't cause the preflight check to fail, should it? (Also react-scripts should probably update their eslint version)

> [email protected] test /Users/gmauer/code/craeslint
> react-scripts test


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": "5.6.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:

  /Users/gmauer/code/craeslint/node_modules/eslint (version: 5.6.1) 

Expected Behavior

tests run fine - there is only a difference in patch level of eslint

Actual Behavior

I get the following

> [email protected] test /Users/gmauer/code/craeslint
> react-scripts test


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": "5.6.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:

  /Users/gmauer/code/craeslint/node_modules/eslint (version: 5.6.1) 
@Timer
Copy link
Contributor

Timer commented Oct 2, 2018

Right now, this is intentional. We want to find an exact version match. We've actually never supported installing ESLint alongside Create React App, so this warning is fine IMO.

For now, please match the version or disable the check with the suggested environment variable.

@Timer Timer changed the title CRA2 preflight check fails when minor eslint version differences Allow patch level differences in preflight check Oct 2, 2018
@gaearon
Copy link
Contributor

gaearon commented Oct 2, 2018

@togakangaroo Could you clarify why you're installing ESLint inside your project? Is it for editor integrations or something else?

@schematis
Copy link

schematis commented Oct 2, 2018

I'm running into this as well.

The reason I'm installing it is because Yarn doesn't recognize it as being installed in order to satisfy peer dependencies of other packages (ie. eslint-config-airbnb).

@silverwind
Copy link

Could you clarify why you're installing ESLint inside your project

In my case, I have it to lint files outside of src. I'd say this check should at least respect semver.

@goncy
Copy link
Contributor

goncy commented Oct 5, 2018

My case is that i use a yeoman generator for copying my usual react lint rules, i can also use this with non-cra projects

@gaearon
Copy link
Contributor

gaearon commented Oct 5, 2018

Would allowing patch-level differences for ESLint specifically satisfy most people in this thread?

@gaearon
Copy link
Contributor

gaearon commented Oct 5, 2018

Note you can ignore the check (just as it says) by putting

SKIP_PREFLIGHT_CHECK=true

to a file called .env in your project root.

@goncy
Copy link
Contributor

goncy commented Oct 5, 2018

Note you can ignore the check (just as it says) by putting

SKIP_PREFLIGHT_CHECK=true

to a file called .env in your project root.

Yes, my actual solution was adding an .env file with that flag to the generator.

The problem with this is that i think the version mismatch between eslint versions is not that important (maybe i'm wrong), but to solve this problem i add the flag to my .env, maybe doing that i supress another really important warnings. Except for jest, is really important to do this preflight checks for dev dependencies?

@gaearon
Copy link
Contributor

gaearon commented Oct 5, 2018

People have definitely complained about broken ESLint before after installing different versions. But yeah patch shouldn’t make a big difference. Although the fact that it even exists up the tree can cause issues by itself.

@togakangaroo
Copy link
Author

So to fill in the picture, my own use case is that I have emacs checking my code with eslint. To do this correctly I want it to use the actual version from in my project so I want it to use npx eslint. This means that I have to have it in my project dependencies directly.

I would imagine anyone else who wants to use it in their Dev workflow would have the same. What are the issues that mismatched versions might cause? Is there no way around those?

@Apollo725
Copy link

Apollo725 commented Oct 9, 2018

Is there any other way without creating new .env file including 'SKIP_PREFLIGHT_CHECK=true' ?
Error says 'That will permanently disable this message but you might encounter other issues.' so I don't want to face on other issues

@silverwind
Copy link

silverwind commented Oct 9, 2018

Would allowing patch-level differences for ESLint specifically satisfy most people in this thread?

eslint is a project that follows semver, so minor version differences are compatible too. Suggesting you bark only on major version differences, like for example:

semver.diff(yourVersion, userVersion) === 'major'

@ywwhack
Copy link

ywwhack commented Oct 23, 2018

I have a project which includes both server/client codes.

Project structure like below:

├── README.md
├── config
├── client
├── logs
├── nodemon.json
├── package-lock.json
├── package.json
└── src

Asume server code root path is ProjectRootPath, client code root path is ProjectRootPath/client

When i run npm run build in the client folder, it tell me babel-eslint version conflict with ProjectRootPath/node_modules/babel-eslint, it conflict with my server code root path(not client code root path), is it a bug?

@niccololampa
Copy link

I am encountering this error too. I am using eslint and prettier for my vscode, so it will auto format my code when saved in VScode.

These are the steps that I have implemented that led to the error in code.

https://medium.com/quick-code/how-to-integrate-eslint-prettier-in-react-6efbd206d5c4

Thanks.

@mptorz
Copy link

mptorz commented Nov 11, 2018

I have exactly the same issue as @niccololampa

I applied the fix with editing a .env file in my root, but that kinda feels like a temporary solution and I wouldn't want that to lead to further errors.

@bugzpodder
Copy link

bugzpodder commented Nov 11, 2018

So eslint is already part of react-scripts, so there should be available as part of npm scripts. I would just not install a different copy in your project. Goto your package.json and remove eslint entry from dependencies or devDependencies.

This works fine for me using vscode + eslint plugin.

@niccololampa
Copy link

niccololampa commented Nov 16, 2018

Discovered the solution for my case. For those like me trying to install the Airbnb eslint styling. Follow these steps.

The eslint-config airbnb requires the following eslint, eslint-plugin-import, eslint-plugin-react, and eslint-plugin-jsx-a11y all of which are already installed in the create-react-app. The problem arises from duplicate installation resulting from the command : npx install-peerdeps --dev eslint-config-airbnb

So the solution is just call the following command:

npm install --save-dev eslint-config-airbnb 

This will just install the airbnb configuration and would not duplicate any packages installed already in create-react-app. Next is to create a .eslintrc file in your root file and insert the following code:

{
  "extends": ["react-app", "airbnb", "plugin:jsx-a11y/recommended"],
  "plugins": ["jsx-a11y"]
}

@mptorz

@silverwind
Copy link

These kind of solutions will not work correctly for the linting done in dev mode, because those use the eslint config from webpack only which is set up to ignore eslint's config files. So your CLI and editor-based linting will use different rules from the linting done in dev mode.

@joserocha3
Copy link

joserocha3 commented Nov 17, 2018

I forked this repo and (mostly) removed eslint from the react-scripts package. You can install eslint as you see fit in your project without any errors or .env variables.

You should still make sure you are linting for the react recommended issues.

https://github.com/joserocha3/create-react-app-eslintless

@rafsawicki
Copy link

rafsawicki commented Dec 11, 2018

I'm having the same problem with the similar setup as @ywwhack . Is there any reason to check a parent node_modules directory for an eslint version? I thought that node won't look into parent if it finds a eslint package in a project node_modules folder.

@AdamLantz
Copy link

AdamLantz commented Dec 13, 2018

Also encountering this issue. It seems that this was historically not regarded as an issue though.

#1355 (comment)

@Shelagh-Lewins
Copy link

I used @niccololampa's suggestion and put the eslint config in package.json, replacing what create-react-app had put in. Seems to work well.

@AdamLantz
Copy link

I wonder if adding some specificity to the skip variable could solve the issue (e.g. SKIP_PREFLIGHT_CHECK=eslint).

Rather than saying you're knowingly skipping all the preflight checks, you could specify which preflight checks to skip.

@lededje
Copy link

lededje commented Jan 10, 2019

I've experienced this issue when using a mono repo that contains a root, base, eslint config with variations for front end and node apps further down. A way of disabling only eslint would be most welcome. I had a quick Google for the other things prelight manages, does anyone have any details?

@malik-devops
Copy link

on windows i've the same problem but i've done yarn add cross-env -D in the terminal and i've modified this line in the file name's package.json.
"scripts": { "start": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts start", },. And after i've done yarn start now it's working.

@alistair-hmh
Copy link

alistair-hmh commented Jan 29, 2019

I'm also running into this issue when using Yarn Workspaces. Even using "nohoist": ['**/eslint'], with head node_modules/eslint/package.json revealing "version": "5.6.0", CRA still tries to pick [email protected] from <workspace-root>/node_modules/eslint.

When examining the directory structure the packages look like they get hoisted just fine, but perhaps CRA does not obey Yarn Workspaces nohoist options?

@ccjx
Copy link

ccjx commented Feb 7, 2019

Is there an issue number with a writeup of what the issues are with a different version of eslint so that someone else can potentially patch the defect?

@piotr-cz
Copy link
Contributor

My use case is that I have installed other package which depends on eslint.
I think good practice would be showing a warning that the SKIP_PREFLIGHT_CHECK=true is enabled after starting development server

@piotr-cz
Copy link
Contributor

Like moving flag check to verifyPackageTree.js and adding following lines: adding following lines:

if (process.env.SKIP_PREFLIGHT_CHECK === 'true') {
  console.log(`Warning: ${chalk.bold('SKIP_PREFLIGHT_CHECK')} is set to true`);
  console.log(`Having wrong version of following packages may break your setup: ${depsToCheck.join(', ')}.\n`)
  return
}

@jgdodson
Copy link

jgdodson commented Mar 4, 2019

I have a project which includes both server/client codes.

Project structure like below:

├── README.md
├── config
├── client
├── logs
├── nodemon.json
├── package-lock.json
├── package.json
└── src

Asume server code root path is ProjectRootPath, client code root path is ProjectRootPath/client

When i run npm run build in the client folder, it tell me babel-eslint version conflict with ProjectRootPath/node_modules/babel-eslint, it conflict with my server code root path(not client code root path), is it a bug?

@ywwhack I think you need to put root: true in your client/.eslintrc to indicate that ESlint shouldn't look in parent directories for a config file.

@latipun7
Copy link

latipun7 commented Mar 4, 2019

I think you need to put root: true in your client/.eslintrc to indicate that ESlint shouldn't look in parent directories for a config file.

@jgdodson imo it won't work. It only skip the eslint configuration, not eslint package. For example he have eslint v5.13.0 in his root folder, but in client (create-react-app) installed eslint v5.12.0. When run or build, the preflight-check found it conflict.

I'm sorry if I wrong here. I'm still newbie, and don't know to resolve if that above is the case. Thanks.

@latipun7
Copy link

latipun7 commented Mar 8, 2019

@ywwhack :

I have a project which includes both server/client codes.

Project structure like below:

├── README.md
├── config
├── client
├── logs
├── nodemon.json
├── package-lock.json
├── package.json
└── src

Asume server code root path is ProjectRootPath, client code root path is ProjectRootPath/client

When i run npm run build in the client folder, it tell me babel-eslint version conflict with ProjectRootPath/node_modules/babel-eslint, it conflict with my server code root path(not client code root path), is it a bug?

@rafsawicki :

I'm having the same problem with the similar setup as @ywwhack . Is there any reason to check a parent node_modules directory for an eslint version? I thought that node won't look into parent if it finds a eslint package in a project node_modules folder.

My solution:
I solved this but really I don't know the real cause. I just switch out the server-client folder structure so it's look like this:

├── node_modules
├── public
├── server
    ├── node_modules
    ├── .eslintrc.yaml
    ├── index.js
    ├── package.json
    └── yarn.lock
├── src
├── .gitignore
├── package.json
├── README.md
└── yarn.lock

I don't know is it because I switch out the structure or is it because I use yarn. I'm sorry, I'm just noob newbie m(_ _)m

@kamlekar
Copy link

I manually uninstalled and installed the actual version. Hope that doesn't bring any issues later.

@privateOmega
Copy link

@ywwhack Did you ever find a solution to this? I am also using the same folder structure and is stuck at this point.
@gaearon @Timer May I suggest a solution, to have an additional option in newer CRA versions eg. --skip-linting, so that eslint and its dependencies won't be installed and then users who require linting can install whatever linting tools they prefer, that could solve problems like mine so I could install whatever plugins I want and will be compatible with eslint version in the project root.

@StephenHaney
Copy link

StephenHaney commented Aug 13, 2019

This isn't strictly related to ignoring patch level changes, but may contribute to the bigger convo. If not, I can remove it:

In a yarn workspaces monorepo setup (with nohoist on for everything):
CRA directory's node_modules correctly has eslint 5.16.0, but further up the parent's package.json has eslint as well (used for linting all the other packages in the repo).

If I peg the parent's ESLint to 5.16.0, CRA doesn't complain... but then I have to use that for all my packages. Besides missing the improvements made to ESlint since, if one of the other packages had a similar requirement for a different version I'd just be stuck.

Pinning my parent to 5.16.0 for now, but I agree a --skip-linting type flag could be useful for folks that want to use CRA in a multi-package repo that already has global linting.

@timini
Copy link

timini commented Mar 6, 2020

this worked for me

"nohoist": [
      "**/webpack"
    ]

mydiemho pushed a commit to microsoft/VoTT that referenced this issue Jun 1, 2020
Create-react-app does not support installing eslint.  We could turn off
PREFLIGHT_CHECK, but that could hide other issues.  Until this issue (facebook/create-react-app#5247) is addressed, will stick with tslint for now
@msalsbery
Copy link

msalsbery commented Jun 11, 2020

I hope this issue is still being looked into!

With eslint replacing the deprecated tslint this year, it would be nice to not have to use the SKIP_PREFLIGHT_CHECK environment variable or worse, be stuck with an old eslint up the project tree from a CRA app!

I’d be happy with something like SKIP_PREFLIGHT_CHECK=eslint ... seems like that would be a relatively simple compromise

@nalendro16
Copy link

I had this issue after changin some file names, recently i delete node_modules on my project directory then npm start didnt, work.

then try this:

  1. So i re install npm in my project directory with npm install
  2. Delete node_modules/eslint from project directory manualy
  3. make .env on project root directory
  4. then type SKIP_PREFLIGHT_CHECK=eslint
  5. and npm start

hope can help

@spgandhi
Copy link

SKIP_PREFLIGHT_CHECK=eslint does not work. SKIP_PREFLIGHT_CHECK=true works instead.

@ernestostifano
Copy link

This was sufficient for me to stop using CRA and manually setup the whole thing. (My comment might not be that useful, but this issue isn't either after two years of being ignored)

@LujiAnna
Copy link

LujiAnna commented Jan 4, 2021

on windows i've the same problem but i've done yarn add cross-env -D in the terminal and i've modified this line in the file name's package.json.
"scripts": { "start": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts start", },. And after i've done yarn start now it's working.

Thank you.
This led me do this yarn add cross-env, then yarn start. Works fine now.
I didn't modify anything in the .json

@Ni-2
Copy link

Ni-2 commented Jan 19, 2021

I had the same problem with CRA and it's eslint 5.**. Creating .env with SKIP_PREFLIGHT_CHECK=true helped only locally. I didn't want to send .env to git so when I tried to deploy the error throwed again and the build crushed.
The decision is simple: to update create-react-app by npm install --save --save-exact [email protected]
Look here -> CHANGELOG.md
My version of CRA was 2.18. When I upgraded it to 4.01 the error has gone!
Before upgrading remove node_modules and package-lock.json (not package.json).
After upgrading do npm install.

@zirkelc
Copy link

zirkelc commented Sep 28, 2021

I have just encountered this issue in my monorepo regarding webpack. I have installed webpack v5 in my project root and react-scripts with its dependency to webpack v4 in a sub-folder ./app.

When executing npx react-scripts in ./app it should use the local node modules from ./app/node_modules with the webpack correct version. However, the verifyPackageTree.js goes up the directories and checks every node_modules folder. Would't it be possible to stop at the local folder if all required dependencies exist in the correct version?

@c9cuu
Copy link

c9cuu commented Jul 10, 2022

I have just encountered this issue in my monorepo regarding webpack. I have installed webpack v5 in my project root and react-scripts with its dependency to webpack v4 in a sub-folder ./app.

When executing npx react-scripts in ./app it should use the local node modules from ./app/node_modules with the webpack correct version. However, the verifyPackageTree.js goes up the directories and checks every node_modules folder. Would't it be possible to stop at the local folder if all required dependencies exist in the correct version?

I think you are right

@mohamedmehdigara
Copy link

  1. Delete node modules
  2. Delete package-lock.json
  3. npm install --legacy-peer-deps
  4. npm audit fix --force
  5. npm start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests