Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typescript outDir setting in tsconfig.json not working

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.

like image 989
aryzing Avatar asked Aug 13 '17 13:08

aryzing


People also ask

Does TSC use Tsconfig?

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.

What is the use of Tsconfig json file in TypeScript?

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.


1 Answers

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.

like image 78
Saravana Avatar answered Sep 22 '22 09:09

Saravana