SyntaxError: Unexpected token :at createScript (vm.js:80:10)

1,683 views
Skip to first unread message

prasad....@gmail.com

unread,
Aug 5, 2018, 4:36:13 AM8/5/18
to Angular and AngularJS discussion

Below is source and getting SyntaxError: Unexpected token :at createScript (vm.js:80:10) .
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}

let greeter = new Greeter("world");



Please help to find complete error trace .
PS D:\my-app\ts-hello> node .\Greeter.ts D:\my-app\ts-hello\Greeter.ts:2 greeting: string; ^ SyntaxError: Unexpected token : at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:616:28) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3 PS D:\my-app\ts-hello> PS D:\my-app\ts-hello>

Sander Elias

unread,
Aug 6, 2018, 1:30:09 AM8/6/18
to Angular and AngularJS discussion
Hi Prasad,

You are aware that you are asking in an Angular channel, right?
You are running your code with Node. That doesn't support typescript. use ts-node. 
Your class is not valid es2015(js) hence the error. It is valid typescript.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages