question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Here is the fix

https://github.com/nestjs/nest/issues/4900#issuecomment-669743374

Bug Report

I installed nest and start new project. and there is a problem with eslint: in .eslint.js I got error

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

eslint in code also not working, and command npm run lint doesn’t find any problems.

Current behavior

Input Code

.eslintrc.js

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    sourceType: 'module',
    project: 'tsconfig.json'
  },
  plugins: ['@typescript-eslint/eslint-plugin'],
  extends: [
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'prettier',
    'prettier/@typescript-eslint',
  ],
...
};

I didn’t change anything actually.

Environment


Nest version: 7.2.0
 
For Tooling issues:
- Node version: 13.10.1
- Platform:  Linux mint

webstorm, npm 6.13.7.

is it reproduced or is it just me?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

52reactions
ghostcommented, Nov 19, 2020

In my opinion, NestJS creates an erroneous configuration.

The file .eslintrc.js shoud look like this:

module.exports = {
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint/eslint-plugin'],
  extends: [
    'plugin:@typescript-eslint/recommended',
    'prettier/@typescript-eslint',
    'plugin:prettier/recommended',
  ],
  root: true,
  env: {
    node: true,
    jest: true,
  },
  ignorePatterns: ['.eslintrc.js'], // !!! new and important part !!!
  rules: {
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
  },
};

By adding ignorePatterns: ['.eslintrc.js'] eslint is told to ignore the .eslintrc.js file itself.

Otherwise it results in an error, because eslint tries to lint the .eslintrc.js file, even though it is not included in the tsconfig.json configuration.

See also https://github.com/typescript-eslint/typescript-eslint/issues/967#issuecomment-530907956.

38reactions
stvnwrgscommented, Oct 12, 2020

Adding "createDefaultProgram": true to the tsconfig, after doing https://github.com/nestjs/nest/issues/4900#issuecomment-669743374 fixed it for me.

  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json",
    "sourceType": "module",
    "createDefaultProgram": true
  },
  ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

"parserOptions.project" has been set for @typescript-eslint ...
Parsing error : "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: /Users/Dan/site ...
Read more >
"parserOptions.project" has been set for @typescript-eslint ...
I have tried to change the include config as following, the error still be there. // 1. Error about js file { ...,...
Read more >
Solve Typescript error "parserOptions.project" has been set for ...
Solve Typescript error "parserOptions.project" has been set for @typescript-eslint/parser. TL:DR: Add the file to the "include" array in your tsconfig.json.
Read more >
IDE displays ESLint error "'parserOptions.project' has been set ...
IDE displays ESLint error "'parserOptions.project' has been set for '@typescript-eslint/parser'" in ".vue" files, but CLI works properly. image.png
Read more >
How to fix VSC ESLint error "The file must be included in at ...
Parsing error : "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found