How to fix Cannot read configuration file 'tsconfig.json' in TypeScript
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.
Quick fix
Fixes TS5058
ls -la tsconfig.json- Verify tsconfig.json exists in your project root
- Create a tsconfig.json if missing
- Validate tsconfig.json syntax using a JSON validator
- Run tsc from the correct working directory
ls -la tsconfig.jsonCannot read configuration file 'tsconfig.json'
What this error means
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.
Typical symptoms
- TypeScript compiler fails with configuration error on startup
- IDE shows unable to resolve TypeScript project configuration
- ESLint or other tools report parsing errors related to tsconfig
- Build scripts fail when invoking tsc command
- Different behavior when running TypeScript from different directories
Common causes
- tsconfig.json file is missing from the project root directory
- The working directory when running tsc is different from where tsconfig.json is located
- tsconfig.json contains invalid JSON syntax (unclosed braces, trailing commas, etc.)
- The extends property in tsconfig.json references a non-existent configuration file
- File permissions prevent TypeScript from reading the tsconfig.json file
- ESLint or other tools are configured to look for tsconfig.json in the wrong location
- tsconfig.json was moved or deleted after the build process started
How to fix "Cannot read configuration file 'tsconfig.json'"
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.jsonAdvanced notes
When 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.
Frequently asked questions
- What does "TS5058" mean?
- json configuration file but was unable to. 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.
- How do I fix "TS5058"?
- 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.
- What causes "TS5058"?
- tsconfig.json file is missing from the project root directory The working directory when running tsc is different from where tsconfig.json is located tsconfig.json contains invalid JSON syntax (unclosed braces, trailing commas, etc.)
- Is the "TS5058" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐TypeScript Official Documentation
- ๐TypeScript: What is a tsconfig.json(Official Docs)
- ๐TypeScript: TSConfig Reference(Official Docs)
- ๐
- ๐