Error "Unknown file extension ".ts"" when running TypeScript in Node.js
Hi! I'm new to TypeScript and trying to run my first project. I installed Node.js, created a file `index.ts` with simple code:
```typescript
const greet = (name: string): string => {
return `Hello, ${name}!`;
};
console.log(greet("World"));
```
I'm trying to run it via `node index.ts`, but I get the error:
`TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\\projects\\test\\index.ts`
I already installed TypeScript globally via `npm install -g typescript`, but that didn't help. I also tried installing `ts-node` — the error remains.
My `package.json` looks like this:
```json
{
"name": "test-project",
"version": "1.0.0",
"type": "module"
}
```
Tell me, what am I doing wrong? How do I properly set up the project to run TypeScript?
No answers yet.
Log in to leave an answer