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

What code were you trying to parse?

A new, empty file.

What did you expect to happen?

No eslint error should occur in the VS Code IDE for the new file.

What actually happened?

When creating a new file in my src dir (which is in tsconfig.json) in any of my TypeScript projects, in VS Code, the following error immediately appears on the file (via the VS Code ESLint extension):

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

Versions

package version
@typescript-eslint/parser 2.6.0
TypeScript 3.6.3
ESLint 6.6.0
node 12.12.0
npm 6.12.1

Also, MacOS 10.14.6 and VS Code 1.39.2.

I know this issue has been mentioned several times in this repo, but it seems like they’re all closed. The issue was supposedly resolved in 2.6.0 of the parser, but it’s not fixed for me.

The new file I am creating are definitely in a directory that is included in tsconfig.json. The error disappears when I use Reload Window in VS Code, but I’d rather not want to do that for every new file I create, primarily because I have several scripts that run when a VS Code workspace is opened, and so I’d have to wait a few minutes after reloading the window.

.eslintrc.js:

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "tsconfig.json"
  },
  "plugins": ["@typescript-eslint"],
  "extends": ["plugin:@typescript-eslint/recommended"]
}

tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "module": "CommonJS",
    "outDir": "./dist/",
    "resolveJsonModule": true,
    "rootDir": "./src/",
    "strict": true,
    "target": "ES2020"
  },
  "include": ["./src/"],
  "exclude": [
    "**/build/**",
    "**/coverage/**",
    "**/dist/**",
    "**/node_modules/**"
  ]
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 14
  • Comments: 21 (9 by maintainers)

Most upvoted comments

woo hoo, awesome @garyking - you’ve found the repro! Thanks

Typescript doesn’t like to be consistent, apparently 😞 If you provide ./src/, then it will ask us to watch the path <absolute_path>/src/. If you provide ./src, then it will ask us to watch the path <absolute_path>/src.

The code right now assumes the latter is how the watch path will always look. So when you create a the file: ./src/foo/bar/baz.ts, this is essentially what happens:

  • look for watch callback for path <absolute_path>/src/foo/bar
  • look for watch callback for path <absolute_path>/src/foo
  • look for watch callback for path <absolute_path>/src
    • typescript did register on path <absolute_path>/src/, but string === match means it doesn’t match, ofc.
  • no watch callback found for folder
  • assume file must not be within tsconfig, and error

Now that I know the problem it’s easy to normalise the paths and fix this.

The same problem happened

@diegohaz - your problem is logged in https://github.com/typescript-eslint/typescript-eslint/issues/1110 Workaround is to add an include to your tsconfig.

@bradzacher I managed to narrow down the issue as far as I could. First, here are my files:

tsconfig.json:

{
  "compilerOptions": {
    "module": "CommonJS",
    "outDir": "./dist/",
    "rootDir": "./src/",
    "strict": true
  },
  "include": ["./src/"]
}

.eslintrc.js:

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

I’m using the VS Code ESLint extension.

In VS Code, I create a file, like src/a.ts. I get the error message. If I Reload Window, then the error message is gone. Just like the issue has been described, so far.

The key is "include": ["./src/"] in tsconfig.json. If you change it to "include": ["./src"] (so, the final slash is removed), then the error will not appear.