【问题标题】:Export & Import syntax error with node =>4.6.x [duplicate]节点=> 4.6.x的导出和导入语法错误[重复]
【发布时间】:2017-11-07 14:32:38
【问题描述】:

如果我没记错的话,Node v4.6 以上的 Node 支持 ES6。 创建 ES6 模块工作正常,直到我需要导入和导出这些模块,然后我得到以下错误:

export class Helper {
^^^^^^
SyntaxError: Unexpected token export

我觉得我错过了什么。

对我有用的解决方案

在您的 tsconfig.json 文件中,添加属性

{"module": "commonjs"}

这将保留 ES6 语法和行为,但使用 ES5 方法导入/导出。

【问题讨论】:

    标签: javascript node.js ecmascript-6 node-modules es6-modules


    【解决方案1】:

    这就是你想要的:

    class name {
    
     }
    
    module.exports = name;
    

    【讨论】:

      猜你喜欢
      • 2020-03-30
      • 2019-05-25
      • 2017-12-11
      • 2016-05-22
      • 2013-10-15
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多