admin管理员组

文章数量:1291217

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.

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.

Share Improve this question edited Nov 23, 2016 at 6:30 Serenity asked Nov 23, 2016 at 4:57 SerenitySerenity 4,0548 gold badges49 silver badges97 bronze badges 8
  • Remove the , after 'nav.translatedMessage': 'Social' – Monasha Commented Nov 23, 2016 at 5:03
  • @Monasha Already tried that. It did not work. This exact code worked when i did not use create-react-app. – Serenity Commented Nov 23, 2016 at 5:05
  • Could you post the full error message? – loganfsmyth Commented Nov 23, 2016 at 6:26
  • @loganfsmyth in a screenshot you see an error is in es.js but it is same with en.js too( the code i have posted above). – Serenity Commented Nov 23, 2016 at 6:31
  • So if you look at the line throwing the error, what module is it? Is it your own code? Is it a node module? – loganfsmyth Commented Nov 23, 2016 at 6:35
 |  Show 3 more ments

2 Answers 2

Reset to default 6

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.

I think its because of the ma

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

Try doing this !

本文标签: javascriptUncaught SyntaxError Unexpected token exportStack Overflow