Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile typescript using tsc node module

I'm trying to compile a typescript into JavaScript using tsc node package module. First of all, I've installed the module using npm install -g typescript. In my local directory I've created a file called classes.js containing a valid typescript code. When running tsc classes.js I get the following error: Error reading file "./classes.js": File not found

The error doesn't make much sense, since the file exist. Same error is shown when the absolute file path is used. I'm wondering if there is something wrong with tsc module or am I missing something?

like image 239
Alex Objelean Avatar asked Jan 25 '26 21:01

Alex Objelean


1 Answers

The typescript compiler specifically looks for extensions .str and .ts. Here is the code that resolves input file names:

if(!TypeScript.isSTRFile(normalizedPath) && !TypeScript.isTSFile(normalizedPath)) {
    normalizedPath += ".ts";
}  

The compiler then looks for a file with name normalizedPath, which in your case corresponds to classes.js.ts, which does not exist. In my opinion, the compiler should output a better error message here.

like image 91
Valentin Avatar answered Jan 27 '26 12:01

Valentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!