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

14,083

Solution 1

I figured it out.

The error occurs when Typescript does not have a file to include for compilation.

The simplest solution is to create a tsconfig.build.json file for example and specify the following parameters in it :

{
  "extends": "./tsconfig.json",
  "exclude": ["node_modules", "test", "dist", "dist/**/*spec.ts"],
  "include": ["src/**/*", ".eslintrc.js"]
}

The above example is adapted for NestJS but should work for other projects.

The most surprising thing is that it's only an error that shows up on PHPStorm, the build, it works fine.

Solution 2

FWIW what worked for me with this error was to add ignorePatterns: ['.eslintrc.js'], to the .eslintrc.js file. This line tells eslint to ignore the .eslintrc.js file (since it's not included in the tsconfig declared project rootDir).

Solution 3

Add it to the includes in tsconfig.json:

"include": [
  ".eslintrc.js",
]
Share:
14,083
Sir Mishaa
Author by

Sir Mishaa

Passionate developer about science, IT and complex systems engineering. My favorite stack is NestJS, Vue Typescript, GraphQL and Docker. Actually, I'm deep learning Rust! I am actively looking to move to Canada and work in or near the city of Montreal. Recruiters, if your offer matches, please do not hesitate to contact me. I will be thrilled and excited about working in Canada, it's kind of my childhood dream.

Updated on June 04, 2022

Comments

  • Sir Mishaa
    Sir Mishaa almost 2 years

    I created a new NestJS project which is a very popular NodeJS framework. But I have this error (see title) on my IDE (PhpStorm 2020.2-Beta) and ESLint doesn't work at all.

    I've used the NestJS CLI :

    nest new nestjs-micro
    

    I don't seem to be the only one with this problem, so it would be nice to find the cause of this problem and fix it once and for all.

    I already have an open issue but I haven't had an answer, this is really very problematic.

    If anyone has an idea on how to fix the problem and keeping an ESLint / Prettier integration with PhpStorm, thanks.

    Repro

    // .eslintrc.js
    module.exports = {
      parser: '@typescript-eslint/parser',
      parserOptions: {
        project: 'tsconfig.json',
        sourceType: 'module',
      },
      plugins: ['@typescript-eslint/eslint-plugin'],
      extends: [
        'plugin:@typescript-eslint/eslint-recommended',
        'plugin:@typescript-eslint/recommended',
        'prettier',
        'prettier/@typescript-eslint',
      ],
      root: true,
      env: {
        node: true,
        jest: true,
      },
      rules: {
        '@typescript-eslint/interface-name-prefix': 'off',
        '@typescript-eslint/explicit-function-return-type': 'off',
        '@typescript-eslint/no-explicit-any': 'off',
      },
    };
    
    
    // tsconfig.json
    {
      "compilerOptions": {
        "module": "commonjs",
        "declaration": true,
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "target": "es2017",
        "sourceMap": true,
        "outDir": "./dist",
        "baseUrl": "./",
        "incremental": true
      }
    }
    
    

    Additional Info Screenshot_20200716_233543

    Versions

    Typescript: 3.7.4
    Node: 14.3.0
    ESLint: 7.1.0
    @typescript-eslint/parser: 3.0.2
    Yarn: 1.22.4
    
  • blwinters
    blwinters almost 3 years
    This was also the solution to allow cascading eslintrc files, so that I can adjust linting rules in one subdirectory while still inheriting rules from the root config.
  • Justin Harris
    Justin Harris about 2 years
    I needed to add env: { browser: true, es6: true, jest: true, node: true, }, to .eslintrc.js after doing that.