Skip to content
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

eslint-config-react-app@7.0.0: @typescript-eslint/eslint-plugin should be peer dependency #12400

Open
unional opened this issue May 15, 2022 · 4 comments

Comments

@unional
Copy link

unional commented May 15, 2022

Describe the bug

The current version of eslint-config-react-app defines @typescript-eslint/eslint-plugin and the like as dependency.
This cause eslint to fail when @typescript-eslint/eslint-plugin not resolved uniquely in the dependency tree.

Here is an example:

ESLint couldn't determine the plugin "@typescript-eslint" uniquely.

- ...\node_modules\@typescript-eslint\eslint-plugin\dist\index.js (loaded in ".eslintrc.json")
- ...\node_modules\eslint-config-react-app\node_modules\@typescript-eslint\eslint-plugin\dist\index.js (loaded in ".eslintrc.json » eslint-config-react-app#overrides[0]")

It should be declared as a peer dependency and the consuming repo install it themselves.

In a plugin architecture, when one plugin uses another plugin, it should always be a peer dependency.

This will be a breaking change and must be released as a new major release.

Did you try recovering your dependencies?

Removing lock file and node_modules will not help in this case.

I have also experience this with yarn@3 with node_modules which I tried to dedupe and cannot resolve the problem.

Even when I tried to get all parties to use the same version of @typescript-eslint/eslint-plugin (5.23.0),
It still end up having two links, one under ./node_modules and one under ./eslint-config-react-app/node_modules.

I think that is a bug on yarn@3, but the problem should also be addressed by eslint-config-react-app.

Which terms did you search for in User Guide?

  • @typescript-eslint
  • ESLint couldn't determine the plugin "@typescript-eslint" uniquely.
  • peer dependency
  • eslint-cofnig-react-app

Environment

This happens on all platforms, with npm, yarn@1-3

Steps to reproduce

Create a dummy repo with this package.json:

{
  "name": "typescript-eslint-plugin-peer-issue",
  "private": true,
  "scripts": {
    "lint": "eslint --ext=ts ."
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "5.4",
    "eslint": "^8.15.0",
    "eslint-config-react-app": "^7.0.1"
  }
}

and this .eslintrc.json:

{
  "extends": [
    "react-app"
  ],
  "plugins": [
    "@typescript-eslint"
  ]
}

create a dummy src/index.ts:

export const dummy = {}

Run:

yarn
yarn lint

Expected behavior

ESLint will work

Actual behavior

ESLint failed with:

ESLint couldn't determine the plugin "@typescript-eslint" uniquely.

- ...\node_modules\@typescript-eslint\eslint-plugin\dist\index.js (loaded in ".eslintrc.json")
- ...\node_modules\eslint-config-react-app\node_modules\@typescript-eslint\eslint-plugin\dist\index.js (loaded in ".eslintrc.json » eslint-config-react-app#overrides[0]")

Reproducible demo

https://github.com/unional/typescript-guidelines/tree/main/examples/eslint-plugin-peer

Added some more information here: https://unional.github.io/typescript-guidelines/blog/2022-eslint-plugin-peer-deps

@unional
Copy link
Author

unional commented May 15, 2022

Dup of #11828 but with repro

@unional unional changed the title eslint-config-react-app: @typescript-eslint/eslint-plugin should be peer dependency eslint-config-react-app@7.0.0: @typescript-eslint/eslint-plugin should be peer dependency May 15, 2022
@unional unional changed the title eslint-config-react-app@7.0.0: @typescript-eslint/eslint-plugin should be peer dependency eslint-config-react-app@7.0.0: @typescript-eslint/eslint-plugin should be peer dependency May 15, 2022
unional added a commit to unional/eslint-plugin-harmony that referenced this issue May 16, 2022
unional added a commit to unional/eslint-plugin-harmony that referenced this issue May 16, 2022
@tkaabbc
Copy link

tkaabbc commented Aug 22, 2022

"@typescript-eslint" be declared as a peer dependency maybe is not a mistake.

Because eslint-config-react-app@7.0.0 use @rushstack/eslint-patch/modern-module-resolution. This patch allows a shared ESLint config to bring along its own plugins, rather than imposing peer dependencies on every consumer of the config. For more detail see @rushstack/eslint-patch

require('@rushstack/eslint-patch/modern-module-resolution');

@tkaabbc
Copy link

tkaabbc commented Aug 22, 2022

eslint-config-react-app has already declared plugins with "@typescript-eslint", it is unnecessary declare again in your .eslintrc.json when you extend eslint-config-react-app

Remove the duplicate "@typescript-eslint" from your .eslintrc.json could resolve ESLint couldn't determine the plugin "@typescript-eslint" uniquely. It works for me.

// .eslintrc.json
{
  "extends": [
    "react-app"
  ],
}

@raDiesle
Copy link

How to "remove the duplicate from "@typescript-eslint" " in practice to resolve the issue? Not clear for me.

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

3 participants