获得意外的令牌导出 [英] Getting Unexpected Token Export

查看:151
本文介绍了获得意外的令牌导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中运行一些ES6代码但是我收到了意外的令牌导出错误。

I am trying to run some ES6 code in my project but I am getting an unexpected token export error.

export class MyClass {
  constructor() {
    console.log("es6");
  }
}


推荐答案

你正在使用ES6模块语法。

You are using ES6 Module syntax.

这意味着您的环境(例如node.js)必须支持ES6模块语法。

This means your environment (e.g. node.js) must support ES6 Module syntax.

NodeJS使用CommonJS模块语法( module.exports )而非ES6模块语法( export 关键字)。

NodeJS uses CommonJS Module syntax (module.exports) not ES6 module syntax (export keyword).

解决方案:


  • 使用 babel npm包将您的ES6转换为 commonjs 目标

  • Use babel npm package to transpile your ES6 to a commonjs target


  • 使用CommonJS语法重构。

这篇关于获得意外的令牌导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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