When using a relative parserOptions.project path, I've found that the path is not relative to the config file (e.g. .eslintrc.js) referencing this path, but instead relative to the working directory of the process running the CLI.
From the @typescript-eslint/eslint-plugin docs:

Here's the problem:
When using the eslint CLI in a different working directory compared to where the eslint config file (e.g. .eslintrc.js) is located, then the parserOptions.project path will resolve relative to the working directory of the process rather than the config file referencing the relative path.
Here's an example using a project located at
C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample:
C:\Users\m41n)$ C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample\src\TypeScriptSample\node_modules\.bin\eslint.cmd "C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample\src\TypeScriptSample\Scripts\app\HomePageService.ts" --format="json"By omitting the --config parameter to the CLI, the config will be resolved correctly by eslint. In this case:
C:\Users\m41n\Source\Repos\TT-ESLint-VisualStudioSample\src\TypeScriptSample\.eslintrc.js
Here's the content of the .eslintrc.js file (irrelevant parts omitted for brevity):
module.exports = {
...
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
...
I'll get an parsing error, saying that the file C:\Users\m41n\tsconfig.json could not be found (parserOptions.project path is relative to the working directory of the process, rather than the .eslintrc.js file):
[
{
"filePath": "C:\\Users\\m41n\\Source\\Repos\\TT-ESLint-VisualStudioSample\\src\\TypeScriptSample\\Scripts\\app\\HomePageService.ts",
"messages": [
{
"ruleId": null,
"fatal": true,
"severity": 2,
"message": "Parsing error: File 'C:\\Users\\m41n\\tsconfig.json' not found."
}
],
"errorCount": 1,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"source": "..."
}
]
What did you expect to happen?
I expect the config property parserOptions.project path to resolve relative to the config file rather than the process running the CLI.
Versions
| package | version |
| --------------------------- | ------- |
| "@typescript-eslint/eslint-plugin | 1.9.0 |
| @typescript-eslint/parser | 1.9.0 |
| TypeScript | 3.4.5 |
| ESLint | 5.16.0 |
| node | 11.12.0 |
This can be worked around using tsconfigRootDir:
module.exports = {
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
}
https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#configuration
If you don't specify tsconfigRootDir, we default to using the CWD because that's how the rest of node works, and how the typescript compiler works.
i.e. if you were to unravel all of our code _and_ typescript's code, you'll see that essentially the algorithm for resolving the provided path is essentially:
const rawConfig = fs.readFileSync(
path.resolve(
process.cwd(),
options.tsconfigRootDir || process.cwd(), // note path.resolve(process.cwd(), process.cwd()) === process.cwd()
options.project,
),
);
Thanks for clarifying @bradzacher.
I could have done a better job verifying the path resolving code myself, and I totally overlooked the tsconfigRootDir property. Sorry about that~
I wish you a great evening. 馃樃
I have same problem and given solution doesn't work for me as I have my eslint configuration inside of package.json file and I can't use __dirname there. Also it wouldn't work when using yaml file for eslint configuration. So I can work around that by moving configuration into eslint.js file but I wish there would be solution that would work in those other cases.
Most helpful comment
This can be worked around using
tsconfigRootDir:https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#configuration
If you don't specify
tsconfigRootDir, we default to using the CWD because that's how the rest of node works, and how the typescript compiler works.i.e. if you were to unravel all of our code _and_ typescript's code, you'll see that essentially the algorithm for resolving the provided path is essentially: