How to fix '--listFilesOnly' requires --listFiles in TypeScript
This TypeScript error occurs when you use the --listFilesOnly compiler flag without also enabling --listFiles. The --listFilesOnly option is dependent on --listFiles and requires it to be set first. The fix involves either adding --listFiles to your command or tsconfig.json, or using the correct standalone flag --listEmittedFiles instead.
Quick fix
Fixes '--listFilesOnly' requires --listFiles
# WRONG - missing --listFiles
tsc --listFilesOnly
# CORRECT - include both flags
tsc --listFiles --listFilesOnly
# You can also use the short form
tsc --listFiles --listFilesOnly src/**/*.ts- Add --listFiles flag to your tsc command
- Configure both flags in tsconfig.json
- Use --listEmittedFiles instead for output files
- Check TypeScript version and documentation
# WRONG - missing --listFilestsc --listFilesOnly# CORRECT - include both flagstsc --listFiles --listFilesOnly# You can also use the short formtsc --listFiles --listFilesOnly src/**/*.ts'--listFilesOnly' requires --listFiles
What this error means
The "'--listFilesOnly' requires --listFiles" error appears when you try to use TypeScript's --listFilesOnly compiler option without first enabling the --listFiles option. These are related but distinct compiler flags with specific dependencies. --listFiles is a TypeScript compiler option that prints all files read during compilation, including library files and source files. This is useful for debugging which files TypeScript is including in your build. --listFilesOnly is a variant that depends on --listFiles being enabled. It's designed to work in conjunction with --listFiles, not as a standalone option. When you use --listFilesOnly without --listFiles, TypeScript cannot determine which files to list because the base listing functionality isn't active. The error indicates a misunderstanding of how these compiler options interact. TypeScript requires --listFiles to be enabled first to establish the file listing context, then --listFilesOnly can filter or modify that output.
Typical symptoms
- Compilation fails with error: "'--listFilesOnly' requires --listFiles"
- TypeScript compiler exits with non-zero exit code when using --listFilesOnly flag
- Build scripts or CI/CD pipelines fail when --listFilesOnly is used in isolation
- Error occurs in both command-line usage and tsconfig.json configuration
- The --listFilesOnly flag appears to have no effect before the error occurs
Common causes
- Using --listFilesOnly flag in tsc command without --listFiles flag
- Setting "listFilesOnly": true in tsconfig.json without "listFiles": true
- Misunderstanding that --listFilesOnly is a standalone option (it's not)
- Copying compiler flags from documentation or examples without understanding dependencies
- Using outdated TypeScript documentation that doesn't clarify the dependency
- Confusing --listFilesOnly with the similar but independent --listEmittedFiles flag
How to fix "'--listFilesOnly' requires --listFiles"
When using --listFilesOnly from the command line, you must also include --listFiles:
# WRONG - missing --listFiles
tsc --listFilesOnly
# CORRECT - include both flags
tsc --listFiles --listFilesOnly
# You can also use the short form
tsc --listFiles --listFilesOnly src/**/*.tsThe order doesn't matter, but both flags must be present. After adding --listFiles, the command should execute successfully and list the files.
If you're configuring these options in your tsconfig.json file, set both properties:
{
"compilerOptions": {
"listFiles": true,
"listFilesOnly": true,
// other options...
}
}Then run TypeScript normally:
npx tsc
# or
npm run buildWith both flags enabled, TypeScript will list the files it processes during compilation.
If you want to see only the output files (JavaScript, declaration files, etc.) that TypeScript generates, use --listEmittedFiles instead. This is a standalone flag that doesn't require --listFiles:
# Shows only generated output files
tsc --listEmittedFiles
# In tsconfig.json
{
"compilerOptions": {
"listEmittedFiles": true,
// No need for listFiles or listFilesOnly
}
}Key differences:
- --listFiles: Shows all input files (source + libraries)
- --listFilesOnly: Requires --listFiles, shows filtered list
- --listEmittedFiles: Standalone, shows only output files (.js, .d.ts, etc.)
Verify your TypeScript version and consult the official documentation:
# Check TypeScript version
npx tsc --version
# View help for listFiles options
npx tsc --help | grep -i listConsult the TypeScript compiler options documentation:
- [TypeScript Compiler Options](https://www.typescriptlang.org/tsconfig)
- [Command Line Interface](https://www.typescriptlang.org/docs/handbook/compiler-options.html)
Note: In TypeScript 4.2+, consider using --explainFiles instead of --listFiles for more detailed information about why files were included.
If you encounter this error in automated scripts or CI/CD pipelines, update the configuration:
# Before (failing)
npm run build -- --listFilesOnly
# After (working)
npm run build -- --listFiles --listFilesOnlyFor package.json scripts:
{
"scripts": {
"list-files": "tsc --listFiles --listFilesOnly",
"list-emitted": "tsc --listEmittedFiles"
}
}Run the updated scripts:
npm run list-files
npm run list-emittedFor TypeScript 4.2 and later, use --explainFiles instead for better debugging:
# Modern alternative to --listFiles
tsc --explainFiles
# Output shows why each file was included:
# - Because it matches include pattern in tsconfig.json
# - Because it's imported by another file
# - Because it's a library file
# - etc.In tsconfig.json:
{
"compilerOptions": {
"explainFiles": true
}
}--explainFiles provides more context than --listFiles and doesn't have the dependency issues of --listFilesOnly. It's the recommended approach for debugging file inclusion in modern TypeScript projects.
Advanced notes
### Historical Context and Flag Evolution
The --listFiles and --listFilesOnly flags have an interesting history in TypeScript:
- TypeScript 1.5: --listFiles introduced as a debugging tool
- TypeScript 2.0: --listEmittedFiles introduced as a separate, standalone flag
- Undocumented feature: --listFilesOnly existed as a dependent flag but wasn't well-documented
- TypeScript 4.2: --explainFiles introduced as a modern replacement with better output
The confusion around --listFilesOnly stems from it being a "hidden" or poorly documented feature that depended on --listFiles. Many developers discovered it through trial and error or community knowledge sharing rather than official documentation.
### Alternative Debugging Approaches
Beyond compiler flags, consider these debugging techniques:
1. --traceResolution: Trace module resolution to see how TypeScript finds files
npx tsc --traceResolution2. --diagnostics: Show diagnostic information including file counts
npx tsc --diagnostics3. TypeScript Server Logs: In VS Code, enable TypeScript server logging:
- Open Command Palette (Cmd/Ctrl+Shift+P)
- Type "TypeScript: Open TS Server Log"
- Or set "typescript.tsserver.log": "verbose" in settings
### Understanding the Dependency Chain
The dependency between --listFiles and --listFilesOnly exists because:
1. --listFiles enables the file tracking system
2. --listFilesOnly queries that tracking system
3. Without --listFiles, there's no tracking system to query
This is similar to other dependent flags in TypeScript and other compilers where:
- A base flag enables a feature
- A modifier flag adjusts that feature
- The modifier cannot work without the base
### Migration to --explainFiles
If you're using --listFiles/--listFilesOnly for debugging, consider migrating to --explainFiles:
Benefits:
- Standalone flag (no dependencies)
- More informative output
- Shows reasoning for file inclusion
- Better integration with modern TypeScript features
- Actively maintained and documented
Migration example:
# Old approach
tsc --listFiles --listFilesOnly
# New approach
tsc --explainFilesThe output format differs but provides more valuable information for debugging file inclusion issues.
Frequently asked questions
- What does "'--listFilesOnly' requires --listFiles" mean?
- The "'--listFilesOnly' requires --listFiles" error appears when you try to use TypeScript's --listFilesOnly compiler option without first enabling the --listFiles option. These are related but distinct compiler flags with specific dependencies. --listFiles is a TypeScript compiler option that prints all files read during compilation, including library files and source files.
- How do I fix "'--listFilesOnly' requires --listFiles"?
- This TypeScript error occurs when you use the --listFilesOnly compiler flag without also enabling --listFiles. The --listFilesOnly option is dependent on --listFiles and requires it to be set first. The fix involves either adding --listFiles to your command or tsconfig.json, or using the correct standalone flag --listEmittedFiles instead.
- What causes "'--listFilesOnly' requires --listFiles"?
- Using --listFilesOnly flag in tsc command without --listFiles flag Setting "listFilesOnly": true in tsconfig.json without "listFiles": true Misunderstanding that --listFilesOnly is a standalone option (it's not)
- Is the "'--listFilesOnly' requires --listFiles" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐TypeScript Official Documentation
- ๐TypeScript TSConfig Reference(Official Docs)
- ๐TypeScript Compiler Options Handbook(Official Docs)
- ๐TypeScript GitHub Issues(GitHub)