question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tsc includes previous output in result when allowJs is enabled and "exclude" is non-empty

See original GitHub issue

TypeScript Version: 2.7.0-dev.20171222

Code

For easy access, clone this gist: https://gist.github.com/WasabiFan/6922d6eb6224945ac809c216fdc37089

test.ts:

// Source code here

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "outDir": "out",
    "allowJs": true
  },
  "exclude": [
    "node_modules"
  ]
}

Removing the exclude block or disabling allowJs avoids the issue.

Note that this is an easy state to get into: in my case, I generated a VSCode extension with their official templates and then enabled allowJs. I didn’t realize what was going on until my PC ran out of RAM, as it automatically ran the watch task and the depth grew every time I saved.

Expected behavior:

I can compile the project with tsc as many times as I’d like.

Actual behavior:

PS D:\...> git clone https://gist.github.com/WasabiFan/6922d6eb6224945ac809c216fdc37089 tsc-recursion-demo-gist
Cloning into 'tsc-recursion-demo-gist'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
PS D:\...> cd .\tsc-recursion-demo-gist\
PS D:\...\tsc-recursion-demo-gist> tsc -p .
PS D:\...\tsc-recursion-demo-gist> tsc -p .
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/test.js' because it would overwrite input file.
PS D:\...\tsc-recursion-demo-gist> tsc -p .
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/test.js' because it would overwrite input file.
PS D:\...\tsc-recursion-demo-gist> tsc -p .
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/test.js' because it would overwrite input file.
PS D:\...\tsc-recursion-demo-gist> tsc -p .
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/test.js' because it would overwrite input file.
PS D:\...\tsc-recursion-demo-gist> tsc -p .
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/out/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/out/test.js' because it would overwrite input file.
error TS5055: Cannot write file 'D:/.../tsc-recursion-demo-gist/out/test.js' because it would overwrite input file.

The fix (and the best option) is to exclude the output directory. But given that existing templates don’t do that, I think this is a significant issue. I don’t understand why this doesn’t happen when the exclude block is removed; I assume there’s an internal safety to prevent this problem that’s overridden.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielRosenwassercommented, Dec 23, 2017

I’ll need to chat with @mhegazy to recall the full context on this topic.

0reactions
WasabiFancommented, Jan 13, 2018

That seems reasonable to me. I have two questions/points of clarification:

  • It seems to me that, in a project without any exclude configuration, that scenario is currently unsupported. To be able to do that you would need to override the exclude property – apparently the exclude list implicitly contains outDir unless the former is modified in the config file. Is that right? I would think it odd that a supported use case relies on disabling that implicit behavior.
  • The particular issue I had is perhaps more narrow than I imagined. My hope is to address the “infinitely recursed file structure” issue, which won’t occur if baseDir == outDir as would be the case in the scenario you wanted to support. The problem I had is specific to when baseDir contains outDir, so that a new copy of the files is created rather than being overwritten (which would be benign).
Read more comments on GitHub >

github_iconTop Results From Across the Web

tsc includes previous output in result when allowJs is enabled ...
It seems to me that, in a project without any exclude configuration, that scenario is currently unsupported. To be able to do that...
Read more >
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Read more >
TSC with allowJs compiles its own compiled JS outside rootDir
Documentation about the parameter (from tsconfig.json schema):. Specifies the root directory of input files. Use to control the output directory structure with ...
Read more >
Javascript - vscode-docs
To enable JavaScript inside a TypeScript project, you can set the allowJs property to true in the TypeScript project's tsconfig.json file. Compiling JavaScript ......
Read more >
grunt-ts - npm
Grunt-ts provides a Grunt-compatible wrapper for the tsc command-line ... The npm tool has effectively deprecated peer dependencies, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found