TypeScript cannot locate or read your tsconfig.json file. This occurs when the configuration file is missing, in the wrong location, contains invalid JSON, or when the working directory is incorrect.
This error means TypeScript's compiler (tsc) tried to find and read your tsconfig.json configuration file but was unable to. The tsconfig.json file is essential for TypeScript projects as it defines compiler options, file inclusion/exclusion patterns, and project settings. When TypeScript cannot read this file, it cannot properly configure the compilation process for your project.
First, check that tsconfig.json is present in the root directory of your TypeScript project. Use your file explorer or run this command:
ls -la tsconfig.jsonIf the file is not found, you need to create it.
If tsconfig.json doesn't exist, generate a default one using TypeScript's initialization command:
npx tsc --initThis creates a valid tsconfig.json file with sensible defaults for your project. You can then customize it as needed.
Copy the contents of your tsconfig.json and paste it into an online JSON validator like https://jsonlint.com/ to check for syntax errors. Common issues include:
// Wrong - trailing comma
{
"compilerOptions": {
"target": "ES2020",
}
}
// Correct
{
"compilerOptions": {
"target": "ES2020"
}
}Fix any JSON syntax errors the validator reports.
Ensure you're running the TypeScript compiler from the directory containing tsconfig.json. For example:
cd /path/to/project
npx tscDon't run tsc from a parent directory unless you explicitly specify the configuration file path:
npx tsc -p ./my-project/tsconfig.jsonIf your tsconfig.json uses the extends property, verify the referenced file exists:
{
"extends": "./tsconfig.base.json",
"compilerOptions": {}
}Ensure tsconfig.base.json (or whatever file is referenced) exists in the same directory. If using npm packages like @tsconfig/recommended, install them first:
npm install --save-dev @tsconfig/recommendedIf you're using ESLint, ts-node, or other tools that reference tsconfig.json, configure them to find it correctly. For ESLint, update .eslintrc.js:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
},
};The tsconfigRootDir tells the tool to resolve tsconfig.json relative to the configuration file's directory, not the current working directory.
On Unix-like systems (Linux, macOS), check that you have read permissions on tsconfig.json:
ls -l tsconfig.jsonIf permissions are restricted (e.g., ----------), add read permission:
chmod +r tsconfig.jsonWhen TypeScript searches for tsconfig.json, it starts in the specified directory and walks up the parent directory chain until it finds the file. This means you can store tsconfig.json in a parent directory and TypeScript will find it, but tools like ESLint may not perform this search and will look only in the working directory. For monorepo setups with multiple tsconfig.json files at different levels, explicitly specify the path using the -p flag: tsc -p packages/my-app/tsconfig.json. Additionally, some IDEs like VSCode cache the tsconfig.json configuration, so after fixing the file, you may need to reload the editor window to see changes take effect.
error TS5023: Unknown compiler option 'files'.
How to fix "Unknown compiler option" in TypeScript
Object literal may only specify known properties, and 'name' does not exist in type 'T'. ts(2353)
How to fix 'Object literal may only specify known properties' in TypeScript
Option 'allowImportingTsExtensions' can only be used when either 'noEmit' or 'emitDeclarationOnly' is set.
How to fix 'allowImportingTsExtensions requires noEmit to be enabled' in TypeScript
Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
How to fix "Cannot find name 'process'" in TypeScript
Function expression requires a return type
Function expression requires a return type