Uncaught SyntaxError: Unexpected token export

喜你入骨 提交于 2021-01-02 05:24:51

问题


I have used create-react-app for my project. I am getting an error of

Uncaught SyntaxError: Unexpected token export

The error is in this code

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

I tried installing babel-preset-es2015 and babel-preset-stage-0. Also i included the babel dict/object in package.json as

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

I am still getting an error.


回答1:


I got my answer on README.md of create-react-app. There it says

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.




回答2:


I think its because of the comma

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

Try doing this !



来源:https://stackoverflow.com/questions/40756359/uncaught-syntaxerror-unexpected-token-export

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!