I can't seem to get the outDir
flag working when used in package.json
. Directory structure is pretty simple: tsconfig.json
at the root level, together with a src/
directory and a single index.ts file plus other directories representing other modules.
When running the tsc
command on the index file, it creates a new one beside it instead of in the build directory. What am I doing wrong?
My tsconfig:
{
"compilerOptions": {
"outDir": "build"
}
}
My npm build script:
"build": "tsc src/index.ts"
I'm calling the script from the root dir of the project. Interestingly, running the same script with an --outDir
flag works just fine.
When you pass in files for compilation with tsc src/index.ts
, your tsconfig.json
is ignored.
From the documentation:
When input files are specified on the command line, tsconfig.json files are ignored.
Your npm build script should just be tsc
without passing any files.