Node 5.6 Doesn't Understand ES6?

后端 未结 2 1762
感情败类
感情败类 2021-01-07 15:01

Trying both node and node --harmony but I continue to get the \'SyntaxError: Unexpected token import\' error.

I have two files, A.ts<

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-07 15:18

    Try https://www.npmjs.com/package/ts-node. It allows compiling of typescript a la node.

    Also make sure your tsconfig.json is set to compile with commonjs. https://github.com/Microsoft/TypeScript/wiki/tsconfig.json

    Here is what my tsconfig.json looks like:

    {
      "version": "1.0",
      "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "removeComments": true,
        "sourceMap": false
      }
    }
    

提交回复
热议问题