TS5042

error TS5042: Option ‘project’ cannot be mixed with source files on a command line.

Broken Code ❌

1
npx tsc -p tsconfig.strict.json src/main.ts

Fixed Code ✔️

If you’re using the -p / --project option, it’s not possible to directly pass a source file as an argument to the TypeScript compiler. If you want to specify the files to be compiled while using the project option from the command line interface (CLI), you need to add the desired files to the include section of your TypeScript project configuration:

tsconfig.strict.json
1
2
3
4
5
6
7
8
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist"
},
"extends": "@tstv/tsconfig-common/tsconfig.json",
"include": ["src/main.ts"]
}