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.
Running tsc locally will compile the closest project defined by a tsconfig. json , you can compile a set of TypeScript files by passing in a glob of files you want.
The presence of a tsconfig. json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig. json file specifies the root files and the compiler options required to compile the project.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With