TypeScript: tsc generating TS5055 error when generating declaration files

I’m consistently getting the following error when compiling any .ts file: error TS5055: Cannot write file ‘dist/[source-file-name].d.ts’ because it would overwrite input file.

The compiler should be willing to overwrite the declarations files any time it recompiles. There are no permissions issues and this seems to be a new problem introduced recently since I moved from a stable ts1.7 release to using typescript@next releases (I’m currently on last night’s - i.e. Version 1.8.0-dev.20151210).

I’m using tsc --watch with the following tsconfig.json file:

{
  "compilerOptions": {
    "target": "es6",
    "moduleResolution": "node",
    "module": "commonjs",
    "preserveConstEnums": true,
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "sourceMap": false,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "outDir": "./dist"
  },
  "exclude": ["node_modules", "jspm_packages"],
  "filesGlob": [
    "./src/**/*.ts"
  ]
}

(NOTE - the filesGlob above is not appearing correctly due to github reformatting… it is actually: ./src/[asterix][asterix]/[asterix].ts just in case you thought I have a bad tsconfig)

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 3
  • Comments: 19 (8 by maintainers)

Most upvoted comments

can you add ./dist to the exclude list?

In my understanding “–watch” and “–declaration” in combination dosen´t make sense. TSC generates the .d.ts files (–declaration) and triggers right again because --watch watches the declaration-files too (they end on .ts) and fires because they were changed by itself, resulting in a compile loop. This doesn´t make sense in my eyes. TSC should ignore “.d.ts”-files if the “–declaration” option is activated.

So in case of “–declaration” .d.ts-files are no input files, but output-files and should be treated as such.

Unfortunately one cannot exclude “*.d.ts” in the exclude-option. This would be a workaround but in my case it isn´t recognized.

I seem to be missing something…

The way I have my tsconfig set up, I’m asking tsc to “please generate definition files for me”. It will generate one when there’s not one already there, but then when I change the .ts file it complains and says “I can’t overwrite the one that I just generated”.

A similar argument could be made for the .js files that are emitted by the compiler (i.e. Even though you changed the .ts file and invoked the compiler, I can’t write a new .js file because there is already one there)…

… Again, am I missing something?

On Thursday, December 10, 2015, Mohamed Hegazy notifications@github.com wrote:

can you add ./dist to the exclude list?

— Reply to this email directly or view it on GitHub https://github.com/Microsoft/TypeScript/issues/6046#issuecomment-163798320 .

Is there a reasonable workaround for people who need the declaration option to be compatible with in-place compiling? My workflow is to let Visual Studio handle my typescript build, and then use Visual Studio as my debugger. So it feels like in-place compiling is the most obvious way for this to work.

The directory which has the tsconfig.json file is considered as a root of the application. The “d.ts” files in the root directory or all of its sub directories would be automatically included. if you generate the “d.ts” files in any of the subdirectory of the root, you would see this error. if you generate the “d.ts” file to some other directory outside of the root directory, then you would be fine.

you can change the location of declartion tile by setting the “declarationDir” variable in the tsconfig.json

@NickGrease the compiler thinks it is an input. can you run tsc --listFiles? do you see it there? if not, then its a bug, please provide some additional information for us to be able to reproduce it. if you do see it, then one of your files import module "dist" or have a ///<reference to it. in short an input file is either a file that you pass on the command line, or that is a dependent of one of the files you pass on the command line transitively.

error TS5055: Cannot write file 'dist/index.d.ts' because it would overwrite input file. index.d.ts is not an input file - its a file I just asked to be created. When I compile a .ts file to javascript, I don’t get an error about index.js already existing, so why the error for .d.ts?

While I appreciate the warning, I think we can improve the messaging. It’s a bit of a red herring, much like this discussion. Here’s what I found: I’m working in Windows, not Linux. Case Sensitivity isnt as much of a big deal here in Windows land. I made a change to the class because, at first, it was lower cased, but I preferred the class name starting with upper case. well the previous lower.d.ts was hanging around when i transpiled. This generated the error. The transpiler intended to replace a “Lower.d.ts”, instead it found a “lower.d.ts”. Once I deleted the “lower.d.ts”, this error disappeared. If you could add this to the exception message, it might help some folks resolve this issue. Or better yet, make an exception that raises when such a case occurs. Thanks. Btw, I wouldnt touch javaScript with a ten-foot pole, but TypeScript has made front-end work less anxiety-ridden. Thanks, again!