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

Make @typescript-eslint optional peerDependencies #8376

Conversation

ThewBear
Copy link
Contributor

Problem

Currently eslint-config-react-app requires @typescript-eslint to be installed in every project even the project that doesn't use typescript. This lead to the warning of missing typescript (#6834
, #6859).

Solution

By making @typescript-eslint an optional peerDependencies, non-typescript user doesn't need to installed @typescript-eslint and can get rid of the warning. User who use typescript can installed typescript along with @typescript-eslint/eslint-plugin and @typescript-eslint/parser.

@trollepierre
Copy link

@ThewBear : can you fix the failing job 🙏 ?
I would be great to have the MR!

@ThewBear
Copy link
Contributor Author

The test fails when using yarn PnP.
How to check if typescript is installed in yarn PnP?


overrides: [
{
// Lint tsx only if typescript is installed.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it's not worth it since if you have ts files, you already have to install typescript:

https://stackoverflow.com/questions/60134596/create-react-app-without-typescript-got-error-failed-to-load-parser-types

@amyrlam amyrlam removed their request for review August 24, 2020 05:37
@dominicfraser
Copy link

This looks to be an alternative fix: #9310

Although ESLint excludes node_modules/ by default when actually linting, the overrides rule for TypeScript does scan the dependencies when looking for TypeScript files (using files: '**/*.ts?(x)'). That means that, even if the linted code contains no TypeScript at all, the override triggers. An attempt to load @typescript-eslint/parser is made, which fails due to TypeScript not being installed.

This PR adds an explicit top-level ignore for node_modules/, which appears to prevent this (tested with a vanilla app made using npx create-react-app@latest).

@smakosh
Copy link

smakosh commented Apr 6, 2021

Create an .eslintignore file at the root and include node_modules there and it should work fine

@ThewBear
Copy link
Contributor Author

ThewBear commented Apr 7, 2021

Closing this now as it is too old.

@ThewBear ThewBear closed this Apr 7, 2021
@ThewBear ThewBear deleted the ThewBear-remove-typescript-eslint-peerdeps branch April 7, 2021 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants