Typescript error “Cannot write file … because it would overwrite input file.”

后端 未结 19 1417
醉梦人生
醉梦人生 2021-02-01 12:04

In my Typescript 2.2.1 project in Visual Studio 2015 Update 3, I am getting hundreds of errors in the error list like:

Cannot write file \'C:/{{my-project

19条回答
  •  南笙
    南笙 (楼主)
    2021-02-01 12:27

    There's several possible causes to this.

    • In your tsconfig.json:
      • Set outDir to "dist" or the name of another same-level folder. (prefixing with './' is unnecessary). This is where the build files go.
      • Set allowJs to false or delete the line. Note: enabled, allowJs will conflict with the declaration setting/flag. It isn't enabled by default.
      • Include "dist" (or your build folder) in exclude.
    • In your package.json:
      • Set main to "index" or some other chosen name. Don't prefix with the build folder (eg "dist/index"), nor the unnecessary "./".
      • Set types (modern alias of typings) to "index". Adding the extensions (.d.ts or .js) is unnecessary.

    Though you can have it a million different ways, for the sake of simplicity and developing understanding it's best to stick to common practices at first - like using "dist", simple tsconfig.json and package.json files at the same level in the tree, and so on. Of course, rooting through the files of your node_modules would also deepen your grasp, but there are more rewarding things in life.

提交回复
热议问题