How to fix Cannot find input files matching pattern in TypeScript

TypeScriptBEGINNERMEDIUMUpdated Dec 10, 2025· 116 views

This TypeScript error occurs when the compiler cannot find any source files matching the patterns specified in your tsconfig.json's 'include' or 'files' properties. The fix involves correcting file patterns, verifying file paths, or adjusting your TypeScript configuration to include the correct source files.

Quick fix

Fixes Cannot find input files matching pattern

// Example tsconfig.json
{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs"
  },
  "include": ["src/**/*.ts", "src/**/*.tsx"]
}
  1. Check your tsconfig.json include patterns
  2. Verify the files array if used
  3. Create a simple test file to verify configuration
  4. Check tsconfig.json location and root directory
typescript — error
// Example tsconfig.json
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs"
},
"include": ["src/**/*.ts", "src/**/*.tsx"]
}
Cannot find input files matching pattern

What this error means

The "Cannot find input files matching pattern" error appears when TypeScript's compiler looks for source files to compile but finds none matching the patterns you've specified in your tsconfig.json configuration. This typically happens when: 1. **Incorrect glob patterns**: The patterns in your 'include' array don't match any actual files 2. **Missing files**: The files referenced in your 'files' array don't exist at the specified paths 3. **Wrong directory**: Your tsconfig.json is in the wrong location relative to your source files 4. **Empty project**: There are no .ts/.tsx files in the directories you're trying to include TypeScript needs at least one input file to compile. When it can't find any files matching your configuration, it shows this error to prevent compiling nothing (which would be confusing). This is a configuration issue rather than a code error, and fixing it involves adjusting your tsconfig.json or project structure. The error commonly appears when: - Starting a new TypeScript project with an empty src/ directory - Moving files around without updating tsconfig.json - Using incorrect glob patterns that don't match your file structure - Having typos in file paths or directory names

Typical symptoms

  • TypeScript compilation fails with 'Cannot find input files matching pattern'
  • Running `tsc` or `npx tsc` shows the error with no further compilation output
  • Build tools (webpack, Vite, etc.) fail with TypeScript compilation errors
  • IDE may show configuration warnings about missing source files
  • Project appears to have no TypeScript files to compile
  • Error occurs even with seemingly correct tsconfig.json settings

Common causes

  1. Empty 'include' array or patterns that don't match any files
  2. 'files' array contains paths to non-existent files
  3. tsconfig.json is in wrong directory (not at project root)
  4. Source files are in different location than expected
  5. File extensions missing from glob patterns (e.g., '**/*' instead of '**/*.ts')
  6. Using 'exclude' patterns that accidentally exclude all files
  7. Case sensitivity issues in file paths on case-sensitive filesystems
  8. Project has no .ts/.tsx files in the included directories
  9. Hidden files or directories not being matched by glob patterns
  10. Incorrect use of relative paths in 'files' array

How to fix "Cannot find input files matching pattern"

1Check your tsconfig.json include patterns

First, examine your tsconfig.json's 'include' property. The default is ["**/*"] which matches all files, but if you've customized it, verify the patterns:

json
// Example tsconfig.json
{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs"
  },
  "include": ["src/**/*.ts", "src/**/*.tsx"]
}

Test if your patterns match files:

bash
# Check what files match your patterns
# For pattern "src/**/*.ts"
find src -name "*.ts" | head -5

# For pattern "**/*.ts"
find . -name "*.ts" | head -5

# If no files found, you need to create TypeScript files
# or adjust your patterns

Common pattern issues:
- "src/*" only matches files directly in src/, not subdirectories
- "src/**" matches directories but not files (needs "src/**/*")
- Missing file extensions: "src/**/*" includes all files, not just .ts/.tsx
- Case sensitivity: "Src" vs "src" on Linux/macOS

2Verify the files array if used

If you're using the 'files' array instead of 'include', check each path exists:

json
{
  "compilerOptions": { /* ... */ },
  "files": [
    "src/index.ts",
    "src/utils/helpers.ts",
    "src/types.d.ts"
  ]
}

Verify each file exists:

bash
# Check each file in the files array
ls -la src/index.ts
ls -la src/utils/helpers.ts
ls -la src/types.d.ts

# If any file is missing, either:
# 1. Create the missing file
# 2. Remove it from the files array
# 3. Fix the path if it's incorrect

Important notes about 'files':
- Paths are relative to tsconfig.json location
- Only these exact files will be compiled (no glob patterns)
- Useful for small projects or explicit file lists
- Consider switching to 'include' for flexibility

3Create a simple test file to verify configuration

Create a minimal TypeScript file to test if your configuration works:

bash
# Create a test directory and file
mkdir -p src
cat > src/test.ts << 'EOF'
// Test TypeScript file
const message: string = "Hello TypeScript";
console.log(message);
EOF

Then update your tsconfig.json to include this file:

json
{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "outDir": "./dist"
  },
  "include": ["src/**/*.ts"]
}

Try compiling:

bash
npx tsc

# If successful, you should see:
# - No error messages
# - dist/test.js created (if outDir is set)
# - Or test.js in same directory (if no outDir)

# If still failing, the issue is with tsconfig.json location
# or other configuration
4Check tsconfig.json location and root directory

TypeScript resolves paths relative to the tsconfig.json file. Ensure it's in the correct location:

bash
# Check current directory and tsconfig location
pwd
ls -la tsconfig.json

# If tsconfig.json is in a subdirectory, TypeScript will look
# for files relative to that subdirectory

# Example structure:
# project/
#   ├── tsconfig.json          # Looking for src/ relative to project/
#   └── src/
#       └── index.ts          # ✓ Found: project/src/index.ts

# WRONG structure:
# project/
#   ├── config/
#   │   └── tsconfig.json    # Looking for src/ relative to config/
#   └── src/
#       └── index.ts         # ✗ Not found: config/src/index.ts doesn't exist

Solutions:
1. Move tsconfig.json to project root
2. Adjust paths in tsconfig.json to be relative to its location
3. Use multiple tsconfig.json files with "extends" for subdirectories

For complex projects, you can use project references:

json
// tsconfig.json at project root
{
  "compilerOptions": {
    "composite": true
  },
  "references": [
    { "path": "./packages/client" },
    { "path": "./packages/server" }
  ]
}

// packages/client/tsconfig.json
{
  "extends": "../../tsconfig.base.json",
  "include": ["src/**/*.ts"]
}
5Fix exclude patterns that might be too broad

The 'exclude' property can accidentally exclude all files. Check your configuration:

json
{
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules", "dist", "**/*.test.ts"]
}

Common exclude mistakes:
- "exclude": ["src"] - excludes entire src directory
- "exclude": ["**/*"] - excludes everything
- "exclude": ["./*"] - excludes files in current directory

Debug by temporarily removing exclude:

json
{
  "include": ["src/**/*.ts"],
  // "exclude": ["node_modules", "dist"]  // Comment out to test
}

If compilation works without exclude, your exclude pattern is too broad.
Add patterns back one at a time to find the problematic one.

Remember: 'exclude' only affects files found via 'include', not files imported via 'files' array.

6Use TypeScript's explainFiles for debugging

TypeScript can show detailed information about why files are included/excluded:

json
{
  "compilerOptions": {
    "explainFiles": true
  },
  "include": ["src/**/*.ts"]
}

Run TypeScript with this option:

bash
npx tsc --explainFiles

# Output shows:
# - Files being included and why
# - Files being excluded and why
# - Configuration being used
# - Resolution details

# Example output:
# File '/project/src/index.ts':
#   Matched by include pattern '**/*' in 'tsconfig.json'
# File '/project/node_modules/typescript/lib/lib.es5.d.ts':
#   Library code file

This helps identify:
- Which patterns are matching (or not matching)
- Why certain files are excluded
- Configuration issues

You can also use traceResolution for module resolution debugging:

bash
npx tsc --traceResolution

Advanced notes

### Understanding TypeScript's File Inclusion System

TypeScript uses a multi-step process to determine which files to compile:

1. Explicit files list (files array): Exact file paths, no glob patterns
2. Include patterns (include array): Glob patterns, defaults to ["**/*"]
3. Exclude patterns (exclude array): Removes files from include matches
4. Imported files: Files referenced via import/require//// <reference>
5. Type declaration files: Automatic inclusion of @types packages

### Glob Pattern Reference

| Pattern | Meaning | Example Matches |
|---------|---------|-----------------|
| * | Any string except / | file.ts, test.ts |
| ? | Any single character except / | a.ts, b.ts |
| **/ | Zero or more directories | src/a.ts, src/lib/b.ts |
| {a,b} | Either a or b | {src,test}/*.ts |
| [abc] | Any character in set | [abc].ts matches a.ts, b.ts, c.ts |
| [^abc] | Any character NOT in set | [^abc].ts matches d.ts, e.ts |

### Common tsconfig.json Patterns

Basic project:

json
{
  "include": ["src/**/*"]
}

React project:

json
{
  "include": ["src/**/*.ts", "src/**/*.tsx"]
}

Monorepo structure:

json
{
  "include": ["packages/*/src/**/*.ts"],
  "exclude": ["packages/*/node_modules", "packages/*/dist"]
}

Test files separate:

json
{
  "include": ["src/**/*.ts"],
  "exclude": ["**/*.test.ts", "**/*.spec.ts"]
}

### TypeScript Configuration Inheritance

You can extend a base configuration:

json
// tsconfig.base.json
{
  "compilerOptions": {
    "strict": true,
    "target": "es2020"
  }
}

// tsconfig.json
{
  "extends": "./tsconfig.base.json",
  "include": ["src/**/*.ts"]
}

// tsconfig.test.json
{
  "extends": "./tsconfig.json",
  "include": ["src/**/*.ts", "tests/**/*.ts"]
}

### IDE-Specific Considerations

VS Code:
- Uses the nearest tsconfig.json
- Restart TS server after config changes: Ctrl+Shift+P > TypeScript: Restart TS server
- Can have workspace-specific settings

WebStorm/IntelliJ:
- May cache TypeScript configuration
- Check "TypeScript" settings in Preferences
- May need to mark directories as "TypeScript Sources Root"

Build Tools Integration:
- Webpack: Uses ts-loader or babel-loader with @babel/preset-typescript
- Vite: Built-in TypeScript support, respects tsconfig.json
- esbuild: Fast but may have different behavior with certain tsconfig options

### Empty Projects and Starter Templates

If starting from scratch, consider using:

bash
# Official TypeScript starter
npx tsc --init

# Creates tsconfig.json with common options
# Then create your source files

# Or use a template:
npx create-react-app my-app --template typescript
npx @vitejs/plugin-react my-app --template react-ts

### Debugging Complex Configurations

For complex setups, create a minimal reproduction:

bash
# Create test directory
mkdir ts-test && cd ts-test

# Minimal tsconfig.json
echo '{"include": ["src/**/*.ts"]}' > tsconfig.json

# Minimal source file
mkdir src
echo 'const x: string = "test";' > src/test.ts

# Test compilation
npx tsc

# If this works, gradually add your actual configuration
# until you find what breaks it

Frequently asked questions

What does "Cannot find input files matching pattern" mean?
json configuration. This typically happens when: 1. Incorrect glob patterns: The patterns in your 'include' array don't match any actual files 2.
How do I fix "Cannot find input files matching pattern"?
This TypeScript error occurs when the compiler cannot find any source files matching the patterns specified in your tsconfig.json's 'include' or 'files' properties. The fix involves correcting file patterns, verifying file paths, or adjusting your TypeScript configuration to include the correct source files.
What causes "Cannot find input files matching pattern"?
Empty 'include' array or patterns that don't match any files 'files' array contains paths to non-existent files tsconfig.json is in wrong directory (not at project root)
Is the "Cannot find input files matching pattern" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading