Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript eslint tsconfig resolution error in monorepo

I have the following project structure:

/root
  /serviceA 
  /serviceB
  /serviceC 
  /serviceD 

Not all of the services are typescript / node based, so I want to avoid adding tsconfig into the root. Each service is setup as a complete unit with its own installation of eslint, ts, and own configuration.

Any ts service I open VScode shows the following error:

Parsing error: Cannot read file '/users/{me}/dev/{root}/tsconfig.json'.

This is correct, as there is no such file, so how do I force vscode & eslint to use the individual services configuration files?

like image 422
dendog Avatar asked Aug 11 '20 09:08

dendog


2 Answers

Edit your .eslintrc file with:


module.exports = {
  parserOptions: {
    project: './tsconfig.json',
    tsconfigRootDir: __dirname,
  },
};

Source: https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-488538828

like image 111
Dicren Avatar answered Oct 26 '22 15:10

Dicren


In .eslintrc you can set the path to tsconfig.json.

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

Here’s an example where it is just set for ts files

https://github.com/davidjbradshaw/eslint-config-auto/blob/master/rules/%40typescript-eslint/parser.js

like image 36
David Bradshaw Avatar answered Oct 26 '22 15:10

David Bradshaw