Avatar ·

Error "Unknown file extension .ts" when running TypeScript via Node.js

Hi everyone! I'm new to TypeScript and trying to run my first project. I installed Node.js, created a simple `index.ts` file with this code:\n\n```typescript\nconst greeting: string = "Hello, World!";\nconsole.log(greeting);\n```\n\nThen I ran the command in the terminal:\n\n```bash\nnode index.ts\n```\n\nBut I got this error:\n\n```\nTypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /path/to/index.ts\n```\n\nNode.js version 18, TypeScript installed globally via npm. I tried adding the `--loader ts-node/esm` flag, but it didn't help either — a bunch of other module errors appeared.\n\nPlease tell me how to properly run TypeScript files? Maybe I need to configure something additionally? I just want to compile and run a simple script, without complex configurations.