SyntaxError: Unexpected reserved word on typescript

mikesneider :

I have not a project, just starting to learn typescript, so I have just one file main.ts with this code:

enum MiColor {Red=0, Green=1, Blue=2};
console.log(MiColor);
let backgroundColor = MiColor.Green;

there is not exists a compilation error, but when I try to run the code in my terminal

node main.ts

I got this error. so, why I have a runtime error as node not recognize typescript?

enum MiColor {Red=0, Green=1, Blue=2};
^^^^

SyntaxError: Unexpected reserved word
←[90m    at wrapSafe (internal/modules/cjs/loader.js:1047:16)←[39m
←[90m    at Module._compile (internal/modules/cjs/loader.js:1097:27)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:977:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:877:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)←[39m
←[90m    at internal/main/run_main_module.js:18:47←[39m

node.js version: 12.16.3

typescript Version: 4.0.2

Leonardo Silva :

Even though your file is .ts you are running as if it was JavaScript.

Install ts-node and run from it npm i -g ts-node, then you run your project with ts-node main.ts

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unexpected reserved word 'import' when using babel

unexpected reserved word import in node.js

What is the "type" reserved word in TypeScript?

Unexpected use of reserved word 'let' in strict mode

TypeScript error: Reserved word 'this' used as name

Meteor 1.3 NPM: Unexpected reserved word import

SyntaxError: Unexpected reserved word on running mocha with enzyme

Node.js application SyntaxError: Unexpected reserved word 'class'

Is `Account` a reserved word in TypeScript?

for await gives SyntaxError: Unexpected reserved word inside a async function

SyntaxError: Unexpected reserved word, for await loop

Typescript : SyntaxError: Unexpected token 'export'

Parsing error: Unexpected reserved word 'static'

SyntaxError: Unexpected reserved word => prettier/third-party.js

Unexpected reserved word error using Jest

TypeScript: Unexpected reserved word

Jint "unexpected reserved word"

TypeScript, SyntaxError: Unexpected token {

Jest test of React application with TypeScript SyntaxError... Unexpected reserved word 'interface'

Unexpected reserved word 'await'

Unexpected reserved word 'await' in async function in react

SyntaxError: unexpected reserved word 'await' in async function

Unexpected reserved word 'await' in getting the session id

React JS Unexpected reserved word 'await'

Unexpected reserved word 'await' for react native

Firestore: Uncaught SyntaxError: Unexpected reserved word

SyntaxError: Unexpected reserved word "await"

Uncaught SyntaxError: Unexpected reserved word in a {name} file

How to solve 'Uncaught SyntaxError: Unexpected reserved word (at index.html:93:36)' in Firebase?