10
votes

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.

enter image description here

2
Remove the , after 'nav.translatedMessage': 'Social' - Monasha
@Monasha Already tried that. It did not work. This exact code worked when i did not use create-react-app. - Serenity
Could you post the full error message? - loganfsmyth
@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
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

2 Answers

6
votes

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.

-7
votes

I think its because of the comma

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

Try doing this !