bennettdams / eslintconfig.dev

Collection of curated ESLint configurations
https://eslintconfig-dev.vercel.app/
37 stars 3 forks source link

dependency conflict with eslint #9

Closed mpvosseller closed 4 years ago

mpvosseller commented 4 years ago

After creating a new react app and using this project's instructions the project fails to yarn start or yarn build. Looks like react-scripts fails because it expects to find eslint ^6.6.0 but finds eslint@^7.5.0 (which we instructed the user to install).

Steps to reproduce:

yarn run v1.22.0
$ react-scripts build

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": "^6.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/mpv/Desktop/my-app/node_modules/eslint (version: 7.10.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /Users/mpv/Desktop/my-app/node_modules/eslint is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls eslint in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed eslint.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
mpvosseller commented 4 years ago

Looking at the installation instructions for eslint-config-react-app here I see that their instructions call for installing different versions of the packages than we do. For example they specify the older version of eslint that matches what react-scripts requires.

Wonder if we could just use their installation instructions / versions and append prettier eslint-config-prettier eslint-plugin-prettier

That would currently make: npm install --save-dev eslint-config-react-app @typescript-eslint/eslint-plugin@2.x @typescript-eslint/parser@2.x babel-eslint@10.x eslint@6.x eslint-plugin-flowtype@4.x eslint-plugin-import@2.x eslint-plugin-jsx-a11y@6.x eslint-plugin-react@7.x eslint-plugin-react-hooks@2.x prettier eslint-config-prettier eslint-plugin-prettier

I'll experiment a bit to see if this works.

mpvosseller commented 4 years ago

Ok it looks like eslint-config-react-app and all of its dependencies are actually already included with react-scripts. See eslint-config-react-app installation instructions and react-scripts package.json.

This is great because it means that maintaining the versions that work together is their problem to handle.

Also most of the settings in our example .eslintrc.js file are not needed because they are already included in eslint-config-react-app which we extend.

I think then all we really need to do is:

One caveat worth noting is that by default "yarn start" and "yarn build" will not use our .eslintrc.js file. This can be enabled by setting the experimental environment variable EXTEND_ESLINT=true

It may be better to leave this off however because with it on a running app (via yarn start) will crash on any lint error which isn't great. May be better to just observe lint errors in editor or run eslint manually and run it in CI before running yarn build.

Will continue testing and submit a PR if I don't have any issues.

Any thoughts on this?

bennettdams commented 4 years ago

I can't verify everything you stated, but that probably has to do with my local setup. In the next days I will set up a Docker image & write a small tutorial, which then can be used with VS Code to develop inside a container - that way we can test the configurations completely encapsulated and be 100% sure that we get it right.

I created an issue for that: https://github.com/bennettdams/eslintconfig.dev/issues/10

mpvosseller commented 4 years ago

@bennettdams 👍 Great. And I'll put together a PR today with my best recommendation.

mpvosseller commented 4 years ago

OK, based on my research and tests I created a PR with instructions as I would recommend them today. https://github.com/bennettdams/eslintconfig.dev/pull/11