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

I created a new React Native project with --template typescript

I deleted the template directory which came as part of the boilerplate.

I then proceeded to add ESLint:

module.exports = {
  parser: "@typescript-eslint/parser",
  plugins: ["@typescript-eslint"],
  extends: ["airbnb-typescript-prettier"]
};

However, when I open babel.config.js, I get this error

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: /Users/Dan/site/babel.config.js. The file must be included in at least one of the projects provided.eslint

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

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

As suggested in this issue, you can add createDefaultProgram: true to your parser options as a temporary solution, albeit at the expense of potentially making your IDE more sluggish.

{
  ...
  parserOptions: {
    project: './tsconfig.json',
    createDefaultProgram: true,
  },
}

Comments
  • but what if I want it to be ignored? It is still showing if I add it in exclude array..
  • This is my issue too. I need that file to be ignored.
  • I believe the point is that typescript+eslint relies on the @typescript-eslint parser so categorically requires linted files to be visible to ts. I'm honestly not sure about this use case. Why do you need it to be excluded? I believe the philosophy of typescript-eslint is based on the assumption that all linted files should be part of the project, and all files that are part of the project should be linted (even if they aren't a critical entrypoint for production code)- It would make sense for example to want type errors if in this case you were specifying a bad babel config.
  • There may be more helpful context which i should check out too here