Node 5.6 Doesn't Understand ES6?

后端 未结 2 1742
感情败类
感情败类 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
      }
    }
    
    0 讨论(0)
  • 2021-01-07 15:37

    Modules are still in progress, I'm not sure if trying to throw the flag will fix your error but here's the command:

    $ node --v8-options | grep 'in progress'
    --harmony_modules (enable "harmony modules" (in progress))
    
    0 讨论(0)
提交回复
热议问题