角度:SyntaxError:意外令牌{

时间:2018-11-23 09:43:54

标签: angular unexpected-token

我的导入功能无法正常运行。我是angular的新手。

我的程序很简单。我有2个文件:

customer.ts

class Person {
  constructor(protected name: string, private age: number) {}

  welcome(): string {
    return `Witaj ${this.name}, czy masz ${this.age} lat?`;
  }
}


export class Customer extends Person {
  constructor(name: string, age: number, private advisor: string) {
    super(name, age);
  }

  welcome(): string{
    return `Siema ${this.name}`;
  }
}

example.ts

import {Customer} from "./customer";
let jan = new Customer("Jan", 44, "Agata");
console.log(jan);

我的命令是:ts-node sandbox / example.ts 所有文件都在沙箱文件夹中。

SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)

2 个答案:

答案 0 :(得分:0)

我认为问题出在您的ts节点版本上。

因为我无法重现该问题。

节点:9.8.0

npm:6.4.1

ts节点:7.0.1

答案 1 :(得分:-1)

嘿,在这里检查它:(在控制台上)

https://stackblitz.com/edit/typescript-4xqc14?file=index.ts

希望这会有所帮助!