I actually had this problem the other day; you need to go to your .eslintrc and make sure that the module is there under the parser property of the config. Should look something like this in the end:

{
  //...

  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],

  //...
}

This should cover the essentials regarding dependencies in your linter. Hope it helps.

Edit

I checked GitHub for this issue, might not be the same as the one I had, check this link please.

Answer from bloo on Stack Overflow
🌐
npm
npmjs.com › package › @typescript-eslint › parser
@typescript-eslint/parser - npm
An ESLint parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
🌐
TypeScript ESlint
typescript-eslint.io › packages › parser
@typescript-eslint/parser | typescript-eslint
An ESLint parser used to parse TypeScript code into ESLint-compatible nodes, as well as provide backing TypeScript programs. ✨
🌐
npm
npmjs.com › package › typescript-eslint-parser
typescript-eslint-parser - npm
An ESLint custom parser which leverages TypeScript ESTree. Latest version: 22.0.0, last published: 7 years ago. Start using typescript-eslint-parser in your project by running `npm i typescript-eslint-parser`. There are 94 other projects in ...
      » npm install typescript-eslint-parser
    
Published   Jan 18, 2019
Version   22.0.0
Author   Nicholas C. Zakas
🌐
TypeScript ESlint
typescript-eslint.io › packages › typescript-eslint
typescript-eslint | typescript-eslint
// @ts-check import eslint from '@eslint/js'; import { defineConfig } from 'eslint/config'; import jestPlugin from 'eslint-plugin-jest'; import tseslint from 'typescript-eslint'; export default defineConfig({ plugins: { '@typescript-eslint': tseslint.plugin, }, languageOptions: { parser: tseslint.parser, parserOptions: { projectService: true, }, }, rules: { '@typescript-eslint/no-floating-promises': 'error', // ...
🌐
npm
npmjs.com › package › typescript-eslint
typescript-eslint - npm
Tooling which enables you to use TypeScript with ESLint. Latest version: 8.49.0, last published: a day ago. Start using typescript-eslint in your project by running `npm i typescript-eslint`. There are 2532 other projects in the npm registry ...
      » npm install typescript-eslint
    
🌐
GitHub
github.com › eslint › typescript-eslint-parser
GitHub - eslint/typescript-eslint-parser: An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
Important: This repository is no longer maintained and typescript-eslint-parser will not receive any future updates. There is an actively maintained fork of this project available at https://typescript-eslint.io and published on npm as @typescript-eslint/parser.
Starred by 914 users
Forked by 74 users
Languages   JavaScript 89.6% | Dockerfile 5.5% | HTML 3.4% | TypeScript 1.5%
Top answer
1 of 16
350

Different lint rules for JavaScript and TypeScript files

The problem happens for one of the reasons below:

  1. You're using a rule which require type information and didn't specify a parserOptions.project;
  2. You specified parserOptions.project, didn't specify createDefaultProgram (it will be removed in a future version), and you're linting files not included in the project (e.g. babel.config.js, metro.config.js)

ESLint flat config (version >= 9)

You can use TypeScript rules only on ts files with the following config (also, see the docs):

const tsPlugin = require('@typescript-eslint/eslint-plugin');
const tsEslint = require('typescript-eslint');

/**
 * @type {import('eslint').Linter.FlatConfig[]}
 */
module.exports = [
  // This is just an example for rules specific to JS files
  {
    files: ['**/*.js'],

    rules: {
      'no-duplicate-imports': 'error',
    },
  },

  ...tsEslint.configs.recommendedTypeChecked.map((config) => ({
    ...config,
    files: ['**/*.ts'], // We use TS config only for TS files
  })),

  {
    files: ['**/*.ts'],

    // This is required, see the docs
    languageOptions: {
      parserOptions: {
        project: true,
        tsconfigRootDir: __dirname, // or import.meta.dirname for ESM
      },
    },

    // This is needed in order to specify the desired behavior for its rules
    plugins: {
      '@typescript-eslint': tsPlugin,
    },

    // After defining the plugin, you can use the rules like this
    rules: {
      '@typescript-eslint/no-unused-vars': 'error',
    }
  }
]

ESLint legacy config (version <= 8)

To solve it, update your ESLint config to use TypeScript rules only on TypeScript files:

{
  // ...
  parser: '@typescript-eslint/parser',
  plugins: ["@typescript-eslint"],
  overrides: [
    {
      files: ['*.ts', '*.tsx'], // Your TypeScript files extension

      // As mentioned in the comments, you should extend TypeScript plugins here,
      // instead of extending them outside the `overrides`.
      // If you don't want to extend any rules, you don't need an `extends` attribute.
      extends: [
        'plugin:@typescript-eslint/recommended',
        'plugin:@typescript-eslint/recommended-requiring-type-checking',
      ],

      parserOptions: {
        project: ['./tsconfig.json'], // Specify it only for TypeScript files
        // or `project: true` in typescript-eslint version >= 5.52.0
      },
    },
  ],
  // ...
}

You can set project: true since typescript-eslint 5.52.0.

You can read more about the overrides config on the official ESLint docs: How do overrides work?


Don't lint a specific file

If you don't want to lint the file that is mentioned in the error (e.g. babel.config.js), you can ignore it adding its name to the .eslintignore file:

babel.config.js

Anyway, the step above (about overriding the config for TypeScript files) is important in case your project contains both JavaScript and TypeScript files that you want to lint.

You can also create other overrides for different situations, e.g. a different config for test files, since it can use developer dependencies and run on node environment, instead of browser, or in version >= 9 you can use globals.

2 of 16
119

You can create a separate TypeScript config file (tsconfig.eslint.json) intended for eslint configuration. That file extends tsconfig configuration and setups include key for files that have to be linted.

.eslint.js:

// ...
parserOptions: {
  // ...
  project: "./tsconfig.eslint.json",
  // ...
},
// ...

tsconfig.eslint.json:

{
  "extends": "./tsconfig.json",
  "include": [
    // ...
    "babel.config.js"
  ]
}

Or if you want to ignore it, you can put it into .eslintignore.

.eslintignore:

// ...
babel.config.js
Find elsewhere
🌐
npm
npmjs.com › package › typescript-eslint-parser-for-extra-files
typescript-eslint-parser-for-extra-files - npm
A custom ESLint parser that provides ... @typescript-eslint/parser provides type information mostly well, but if you import extra files (other than *.ts, *.tsx, *.d.ts, *.js, *.jsx, and *.json) it treats it as any type....
      » npm install typescript-eslint-parser-for-extra-files
    
🌐
ESLint
eslint.org › docs › latest › use › configure › parser
Configure a Parser - ESLint - Pluggable JavaScript Linter
The following third-party parsers are known to be compatible with ESLint: ... @typescript-eslint/parser - A parser that converts TypeScript into an ESTree-compatible form so it can be used in ESLint.
Top answer
1 of 3
7

Explanation

If you create a new project with npm init -y and then npm install @typescript-eslint/eslint-plugin, you would see in your package-lock.json:

"node_modules/@typescript-eslint/eslint-plugin": {
  "version": "6.2.1",
  ...
  "peerDependencies": {
    "@typescript-eslint/parser": "^6.0.0 || ^6.0.0-alpha",
    ...
  }
  ...
}

This means @typescript-eslint/eslint-plugin version 6.2.1 needs @typescript-eslint/parser version ^6.0.0 to be in your project.

Meanwhile, here is what you have in your current package-lock.json:

"node_modules/eslint-config-next": {
  "version": "13.4.8",
  ...
  "dependencies": {
    ...
    "@typescript-eslint/parser": "^5.42.0",
    ...
  },
  ...
},

Meaning eslint-config-next needs version 5.42.0, so while installing @typescript-eslint/eslint-plugin, npm founds a versions conflict.

Solution

You can install @typescript-eslint/eslint-plugin version 5.9.0, which expects the version ^5.0.0 of @typescript-eslint/parser :

npm i @typescript-eslint/[email protected]
2 of 3
4

I got a similar issue working with a create-react-app which I was converting to use typescript. As Youssouf suggested, the issue is the conflict of versions between @typescript-eslint and some other sub-modules, such as @typescript-eslint/parser. This was evident by my package-lock.json listing several @typescript-eslint sub-modules as at version 5.6.2.

I fixed this by first running npm i @typescript-eslint/parser@latest to upgrade the sub-modules in my package-lock. I was then able to run npm i @typescript-eslint/eslint-plugin successfully.

🌐
ESLint
eslint.org › docs › latest › extend › custom-parsers
Custom Parsers - ESLint - Pluggable JavaScript Linter
For a complex example of a custom parser, refer to the @typescript-eslint/parser source code.
Top answer
1 of 1
2

after checking at eslint plugin naming convention, found out that I have to install the missing @typescript-eslint as following syntax

npm install --save-dev @typescript-eslint/eslint-plugin

this solved the issue but new error coming that react version is not specified , so added that in "settings" key.

eslintrc.js

// eslint-disable-next-line no-undef
module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 12,
    sourceType: 'module',
  },
  plugins: ['react', '@typescript-eslint'],
  rules: {
    '@typescript-eslint/no-explicit-any': 'off',
    'react/react-in-jsx-scope': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
  },
  settings: {
    react: {
      version: 'latest',
    },
  },
};

package.json

"devDependencies": {
    "@types/classnames": "^2.3.1",
    "@types/react-redux": "^7.1.19",
    "@types/react-router-dom": "^5.3.1",
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "eslint": "^7.32.0",
    "eslint-plugin-import": "^2.25.2",
    "redux-devtools": "^3.7.0",
    "redux-devtools-extension": "^2.13.9",
    "typescript": "^4.4.4"
  }

tsconnfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "noImplicitAny": false,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "downlevelIteration": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"]
}
🌐
Khalil Stemmler
khalilstemmler.com › blogs › typescript › eslint-for-typescript
How to use ESLint with TypeScript | Khalil Stemmler
December 19, 2021 - npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
🌐
GitHub
github.com › typescript-eslint › typescript-eslint
GitHub - typescript-eslint/typescript-eslint: :sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript
:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript - typescript-eslint/typescript-eslint
Starred by 16K users
Forked by 2.9K users
Languages   TypeScript 90.9% | MDX 7.8%
🌐
TypeScript ESlint
typescript-eslint.io
typescript-eslint
The parser and services for linting TypeScript code with ESLint, as well as how tools such as Prettier read TypeScript code.
🌐
TypeScript ESlint
typescript-eslint.io › getting-started
Getting Started | typescript-eslint
ESLint will lint all TypeScript compatible files within the current folder, and will output the results to your terminal. If you're having problems getting this working, please have a look at our Troubleshooting & FAQs.