Search code examples
javascriptjsontypescriptaurelia

How to use --outDir TypeScript compilerOptions


I'm facing an issue where the compiler complains about the following: Cannot write file 'path/file.json' because it would overwrite input file. I did some digging and most solutions suggest to use outDir to fix it. That solutions works fine but I'm not sure what folder to pass to it. Right now I have it set up as follows and the compiler stopped complaining:

outDir: "path/file.json",

I'm not too sure if that's a good idea because I'm basically passing it itself. The Json is just an object that I'm reading from and I'm using an Aurelia project. Any tips or information will be greatly appreciated.

My folder structure


Solution

  • I suspect you don't want this json file to be compiled? Maybe just add it to the "exclude" glob in your tsconfig.json so tsc doesn't process it?

    https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

    I usually split mine into
    src/
    dist/

    Then my tsconfig would have something like

    {
      "compilerOptions": {
        "outDir": "dist"
      },
      "include": [
        "src/**/*"
      ],
    }