首页 > 解决方案 > 我对 TypeScript 还很陌生,遇到了一个错误:Unexpected token 'export'

问题描述

我一直在搜索互联网,但无济于事。

我的代码:

export const MESSAGES = {
    TEST: {
    ONE: 'Hello, world!'
  }
}

配置:

{
    "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "strict": true
    }
  }

编辑:我需要一个 JavaScript 文件。

标签: typescript

解决方案


export关键字是 es6 模块语法,所以commonjs改为esnext.

{
    "compilerOptions": {
      "target": "es6",
      "module": "esnext",
      "strict": true
    }
}

推荐阅读