typescript outDir setting in tsconfig.json not working

后端 未结 4 898
臣服心动
臣服心动 2021-02-05 01:00

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 le

相关标签:
4条回答
  • 2021-02-05 01:12

    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.

    0 讨论(0)
  • 2021-02-05 01:13

    If you are using the incremental compiler option, you may not be getting output if you have deleted / modified files in your outDir but have not removed the .tsbuildinfo file.

    My issue was a bit different, but Google brought me here - so figured others may also.

    0 讨论(0)
  • 2021-02-05 01:14

    This is my folder structure.

    Keep the typescript files in src folder and keep the tsconfig.json in root.

    In tsconfig json file add foldername for outDir in compilerOptions

    "compilerOptions": {    
        "outDir": "build",
        "module": "commonjs",
        "target": "es6",
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noImplicitAny": true,
        "sourceMap": true
      },
    

    and run the below commands.

    just cd to the root folder and type

    tsc

    or

    tsc --outDir .

    which will build the outDir folder with js and map.js files.

    source: https://github.com/Microsoft/TypeScript/issues/10585

    0 讨论(0)
  • 2021-02-05 01:24

    You need to declare your tsconfig file location instead of the file you want to build.

    tsc --build mocks/tsconfig.json
    
    0 讨论(0)
提交回复
热议问题