This TypeScript warning appears when an exclude pattern in tsconfig.json doesn't match any files in the project. While harmless, it often indicates incorrect glob patterns, typos, or outdated exclusion rules that can be safely removed or corrected.
The "exclude pattern does not match any files" message is a warning from the TypeScript compiler indicating that one or more patterns specified in the `exclude` property of your tsconfig.json file don't match any actual files in your project. This is not a compilation-blocking error, but rather a diagnostic message suggesting that your configuration might contain unnecessary or incorrect exclusion patterns. TypeScript raises this warning to help you maintain a clean, accurate configuration file. The warning typically appears during compilation and suggests that: 1. **The pattern is no longer needed**: Files that were previously excluded may have been moved or deleted 2. **The glob syntax is incorrect**: The pattern uses invalid wildcard syntax or path separators 3. **The path doesn't exist**: The pattern references directories that don't exist in your project structure While this won't prevent your code from compiling, it's best practice to clean up unused configuration to avoid confusion and maintain an accurate tsconfig.json file.
TypeScript will usually indicate which pattern doesn't match. Check your tsconfig.json:
{
"compilerOptions": {
"target": "ES2020"
},
"exclude": [
"node_modules",
"dist/**",
"build/**", // <- This might be the problematic pattern
"temp/**",
"coverage/**"
]
}Run the TypeScript compiler with verbose output to see more details:
npx tsc --verboseThis will show which patterns are being evaluated and which ones don't match any files.
Check if the path referenced in the exclude pattern exists in your project:
# List directories at project root
ls -la
# Check if a specific directory exists
ls -d build 2>/dev/null || echo "Directory 'build' does not exist"
# Find all directories matching a pattern
find . -type d -name "temp*" -maxdepth 3If the directory doesn't exist and isn't generated during the build process, you can safely remove that pattern from your exclude list.
Example - removing unused pattern:
{
"exclude": [
"node_modules",
"dist/**",
// "build/**" <- Remove this if 'build' directory doesn't exist
"coverage/**"
]
}Ensure your glob patterns use correct syntax. Common mistakes include:
WRONG - Missing recursive wildcard:
{
"exclude": [
"dist/*.js" // Only matches .js files directly in dist/
]
}CORRECT - Use for recursive matching:**
{
"exclude": [
"dist/**/*" // Matches all files recursively in dist/
]
}WRONG - Windows-style backslashes:
{
"exclude": [
"src\temp\**" // Backslashes don't work
]
}CORRECT - Always use forward slashes:
{
"exclude": [
"src/temp/**" // Forward slashes work on all platforms
]
}Common glob patterns that work:
{
"exclude": [
"**/*.test.ts", // All .test.ts files anywhere
"**/*.spec.ts", // All .spec.ts files anywhere
"node_modules", // Entire node_modules directory
"dist/**", // Everything in dist recursively
"build", // Just the build directory
"src/temp/**/*.js" // Specific nested pattern
]
}If the pattern references files that no longer exist or aren't needed, simply remove it from your tsconfig.json:
Before:
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"exclude": [
"node_modules",
"dist",
"temp", // <- Old temporary directory
"old-build", // <- Removed during refactoring
"scripts/*.js" // <- Scripts moved to TypeScript
]
}After:
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
"exclude": [
"node_modules",
"dist"
]
}Save the file and recompile:
npx tscThe warning should disappear if all patterns now match existing files or have been removed.
If you're having trouble with exclude patterns, consider using include instead, which explicitly lists what should be compiled:
Instead of excluding many directories:
{
"exclude": [
"tests/**",
"docs/**",
"scripts/**",
"examples/**"
]
}Use include to specify exactly what to compile:
{
"include": [
"src/**/*" // Only compile files in src directory
]
}This approach is more explicit and less prone to pattern matching issues. The include property takes precedence, and you can still combine it with exclude for edge cases:
{
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.test.ts", // Exclude test files
"src/**/__mocks__/**" // Exclude mock directories
]
}### Understanding Exclude vs Include Behavior
The exclude property in tsconfig.json doesn't work as an absolute exclusion mechanism. Key points to understand:
Exclude filters include results:
{
"include": ["src/**/*"],
"exclude": ["src/temp/**"]
// Result: All files in src/ except src/temp/
}Exclude doesn't prevent imported files from being compiled:
Even if a file is in the exclude list, it will still be compiled if it's imported by another file that IS included:
// src/index.ts (included)
import { util } from "../excluded/helper"; // Will still be compiled!To truly exclude a file, you must ensure it's not imported anywhere in your included files.
### Default Exclude Behavior
If you don't specify an exclude property, TypeScript automatically excludes:
- node_modules
- bower_components
- jspm_packages
- The outDir directory
This means explicitly listing "node_modules" in your exclude array is redundant unless you're overriding the default behavior.
### Glob Pattern Limitations
TypeScript's glob pattern support is limited compared to other tools:
Not supported:
{
"exclude": [
"**/*.{test,spec}.ts" // Brace expansion doesn't work
]
}Workaround - use multiple patterns:
{
"exclude": [
"**/*.test.ts",
"**/*.spec.ts"
]
}### Project References and Exclude
When using TypeScript project references, exclude patterns in the root tsconfig.json don't affect referenced projects:
// Root tsconfig.json
{
"references": [
{ "path": "./packages/app" },
{ "path": "./packages/shared" }
],
"exclude": ["**/temp/**"] // Only applies to root, not referenced projects
}
// packages/app/tsconfig.json needs its own exclude:
{
"exclude": ["temp/**", "**/*.test.ts"]
}### Debugging Pattern Matching
Use TypeScript's trace resolution to see how patterns are evaluated:
npx tsc --listFilesOnlyThis shows which files TypeScript will compile, helping you verify that your include/exclude patterns work as expected.
### Case Sensitivity
Glob patterns are case-sensitive on Linux/macOS but case-insensitive on Windows:
{
"exclude": [
"Temp/**" // Matches Temp/ on Windows, not temp/ on Linux
]
}For cross-platform projects, use lowercase consistently:
{
"exclude": [
"temp/**" // Works consistently across platforms
]
}Type parameter 'X' is not used in the function signature
How to fix "Type parameter not used in function signature" in TypeScript
Type parameter 'X' is defined but never used
How to fix "Type parameter is defined but never used" in TypeScript
Function expression requires a return type
Function expression requires a return type
Value of type 'string | undefined' is not iterable
How to fix "Value is not iterable" in TypeScript
Type 'undefined' is not assignable to type 'string'
How to fix "Type undefined is not assignable to type string" in TypeScript