Configuring TypeScript ESLint in your monorepo

Charles Stover
Sep 11, 2021

If you are instantiating a TypeScript monorepo with a one-size-fits-all-packages ESLint configuration, you may encounter this error (or some variation) when linting your packages:

Line 0: Parsing error: Cannot read file 'tsconfig.json'Line 0: Parsing error: Cannot read file 'tsconfig.eslint.json'

In particular, this occurred for me when running Create React App’s react-scripts build command in a monorepo package, as it failed to find the ESLint’s TypeScript project configuration file, whether I located it in the root directory or the package directory.

The fix is to override the package’s ESLint configuration as shown here:

{
"extends": ["../../.eslintrc.json"],
"root": false,
"parserOptions": {
"project": "../../tsconfig.eslint.json"
}
}

By telling your package, e.g. packages/package-name/, to load its TypeScript project configuration from two directories higher, this error is resolved.

--

--