javascript - 未捕获的语法错误 : Unexpected token export

标签 javascript reactjs ecmascript-6 create-react-app

我在我的项目中使用了 create-react-app。我收到错误

Uncaught SyntaxError: Unexpected token export

错误在这段代码中

export const ENGLISH = {
  lang: 'en',
  messages: {
      'nav.translatedMessage': 'Social',
  }
};

我尝试安装 babel-preset-es2015 和 babel-preset-stage-0。我还把 babel dict/object 包含在 package.json 中作为

"babel": {
    "presets": [
      "es2015",
      "stage-0"
    ]
  },

我仍然遇到错误。

enter image description here

最佳答案

我在 create-react-app 的 README.md 上得到了答案。上面写着

You may create subdirectories inside src. For faster rebuilds, only files inside src are processed by Webpack.
You need to put any JS and CSS files inside src, or Webpack won’t see them.

关于javascript - 未捕获的语法错误 : Unexpected token export,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40756359/

相关文章:

reactjs - 禁用和启用按钮的样式

jquery - 将 Owl Carousel 2 与 next.js 一起使用并使用react

javascript - 比较两个数组与对象并创建具有不匹配对象的新数组

javascript - JS中如何使用reduce和map new对象来解决重复值?

javascript - webpack 编译器根本不会将 es6 语法转换为旧版本的语法

javascript - 在 Angular 2 中呈现一定数量的子组件

javascript - 如果数组元素以某​​个字母开头,则执行某些操作

javascript - 圆环图在 angularjs 中不起作用

javascript - Opera下onYouTubePlayerAPIReady触发失败

javascript - create-react-app with node express 获取 %PUBLIC_URL%