6

I can't seem to figure out why when running

tsc *.ts

isn't working. It comes with the error: TS6053: File '*.ts' not found. How do I compile all of the .ts files in a folder? Thanks!

3
  • How do you run that command? * is a shell expansion feature.
    – zerkms
    Commented Jun 7, 2018 at 10:16
  • I just use powershell, and usually, I'd assume that *.ts would mean any ts file in a folder. How would you select all the .ts files if you don't use * in the command line? Commented Jun 7, 2018 at 10:20
  • 1
    You can give specific source directory with a command tsc --rootDir <folder>. Better place to define this is tsconfig.json and then you just give the tsc to compile all. Commented Jun 7, 2018 at 10:22

6 Answers 6

5

When running tsc from the command line without a tsconfig present, you need to pass it a file name, i.e. app.ts - it will walk the dependencies for you, so you don't need to use a wildcard.

If you have a tsconfig.json file, just run tsc with no file name argument and it will use the config, which can contain wildcards.

3

Just type tsc without anything. It will compile all .ts files into .js files. If you want to bundle them, type tsc --outFile mybundle.js.

Please note that in this case, bundling only means that all your .js code will be placed in one file. For more elaborate options it's better to create the tsconfig.json, as others have mentioned.

1

I faced the same problem today as you have mentioned, while executing 2 files within a folder which I created some 2-3 months back when started learning Angular. That time I didn't face this issue.

NOTE: That file was un-touched after first time modification and it was successfully executed that time.

I am sure that, below solution is not the ideal one but still it worked for me today.

Scenario: I have a folder which contains "LikesComponent.ts" and "main.ts" file. And I want to execute both my TS files and get the output. So I executed

tsc *.ts && node main.js

I encountered

error TS6053: File '*.ts' not found. Found 1 error.

But when I executed below command, it worked !!!

tsc LikesComponent.ts main.ts && node main.js

1
  • Hello @Frontier, I am going to remove the follow-up question from your answer. Please ask a new question for that. Commented May 3, 2020 at 14:51
1

I faced the same problem, try this command: tsc --outFile file.js file.ts

0

Well, I don't think that is the solution, which is marked as correct, you might new to angular and following Mosh tutorials,

The solution would be just execute the root file where you have imported all other modules, in my scenario, it is main.ts file and below is how I executed it

$tsc main.ts && node main.js

0

you can use this on linux:

ls *.ts | xargs tsc

The xargs command convert the output from the ls command into an argument for the tsc command.

Note that subfolders also work:

ls src/*.ts | xargs tsc

Not the answer you're looking for? Browse other questions tagged or ask your own question.