Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"parserOptions.project" has been set for @typescript-eslint/parser

People also ask

How do you fix parsing error parserOptions project has been set for TypeScript ESLint parser?

The easiest way to solve the error is to add the files in which you get it to your . eslintignore file, which should be located in the root directory of your project, right next to . eslintrc. js .

What is parserOptions project?

parserOptions. This option allows you to request that when the project setting is specified, files will be allowed when not included in the projects defined by the provided tsconfig. json files. Using this option will incur significant performance costs. This option is primarily included for backwards-compatibility.

What is parser in ESLint?

@typescript-eslint/parser - A parser that converts TypeScript into an ESTree-compatible form so it can be used in ESLint.


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)

As from the TypeScript ESLint Parser docs:

parserOptions.project

This option allows you to provide a path to your project's tsconfig.json. This setting is required if you want to use rules which require type information.

(...)

Note that if this setting is specified and createDefaultProgram is not, you must only lint files that are included in the projects as defined by the provided tsconfig.json files. If your existing configuration does not include all of the files you would like to lint, you can create a separate tsconfig.eslint.json.

To solve it, update your ESLint config to the following:

{
  // ...
  overrides: [
    {
      files: ['*.ts', '*.tsx'], // Your TypeScript files extension
      parserOptions: {
        project: ['./tsconfig.json'], // Specify it only for TypeScript files
      },
    }
  ],
  parser: '@typescript-eslint/parser',
  // ...
}

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

Add one line in ".eslintignore":

.eslintrc.js


You need to add that file to your tsconfig include array. See typescript-eslint/typescript-eslint#967 for more details.