节点5.6不了解ES6? [英] Node 5.6 Doesn't Understand ES6?

查看:77
本文介绍了节点5.6不了解ES6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试节点 node --harmony ,但是我继续得到'SyntaxError:Unexpected token import'

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

我有两个文件, A.ts B.ts 。这是他们的样子 -

I have two files, A.ts and B.ts. Here is what they look like-

B.ts

export class B {

}

A.ts

import {B} from './B';

console.log(new B());

哪些结果 -

(function (exports, require, module, __filename, __dirname) { import {B} from './B';
                                                              ^^^^^^
SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:140:18)
    at node.js:1001:3

为什么?

推荐答案

模块仍在进行中,我不知道如果尝试扔标志将修复您的错误,但这里的命令:

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))

这篇关于节点5.6不了解ES6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆