Fix tsconfig.json 'No inputs were found in config file'

By

How to fix the tsconfig.json No inputs were found in config file error in an Astro project by adding an empty TypeScript file or an include path.

~~~

The “No inputs were found in config file” error means TypeScript found a tsconfig.json file but couldn’t find a single TypeScript file to compile. Adding one .ts file, or pointing include at your source folder, fixes it.

A few students of mine had this problem with an Astro project.

Astro by default includes a tsconfig.json file and this file gave them an error in VS Code.

The error was coming from tsconfig.json and it said

No inputs were found in config file

We weren’t writing any TypeScript, so that was a strange issue.

Why does this error happen?

When a tsconfig.json exists, TypeScript assumes there’s something to compile.

If you don’t set include or files, TypeScript looks for .ts and .tsx files in the folder containing tsconfig.json and all its subfolders. If it finds none, it raises this error.

Astro ships a tsconfig.json so the editor tooling works well, even in projects where you write zero TypeScript. So a fresh project with no .ts files can trigger the error out of the box.

You can also hit it when the config points at the wrong place. Maybe you moved your code from src to another folder, or an exclude pattern accidentally matches everything. In both cases TypeScript ends up with an empty list of files.

How to fix it

First, try restarting VS Code. The TypeScript language server sometimes holds on to stale state, and the error disappears after a restart.

If that doesn’t work, add an empty file.ts file in the same folder where there’s the tsconfig.json file. Now TypeScript has one input, and the error goes away.

Or delete tsconfig.json. No config file, no inputs to check.

Unless you plan to use TypeScript, in which case you can configure it to point to the TypeScript files in your project by adding include, from:

{
  "compilerOptions": {
    "moduleResolution": "node"
  }
}

to

{
  "compilerOptions": {
    "moduleResolution": "node"
  },
  "include": [
    "./src/**/*.ts"
  ]
}

Notice that once you add include, TypeScript only looks at the paths you list there. If your files live somewhere else, adjust the glob pattern to match, or the same error comes right back.

If you want to build a clean tsconfig.json from scratch, I built a free tsconfig generator that explains every option.

~~~

Related posts about js: