1

I'm trying to run client-side tests for React reducers using Mocha & Chai and Mocha/Node is complaining about any kind of es6, specifically "import" and "export" statements.

Unexpected token import

Here is my .babelrc file:

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

I also tried installing babel-core and using the method specified in this stackoverflow article: (Babel unexpected token import when running mocha tests)

I am running node version 5.5.0, not sure if that helps. Let me know if I can provide any more info. Thanks in advance.

Community
  • 1
  • 1
Jose
  • 4,880
  • 8
  • 27
  • 49

1 Answers1

-4

I ran into that same issue. Having tried every other solution on stackoverflow and beyond, adding this simple config on package.json did it for me:

  "babel": {
    "presets": [
      "es2015"
    ]
  }

All my ES6 imports worked after that. By the way, I had this same configuration inside webpack.config.js and .babelrc, but apparently this was the only way to make it work for mocha testing as well.

Let me know if that worked for you too.

arakno
  • 428
  • 3
  • 6
  • Please do not duplicate your answers. When you run into multiple questions that would take the same answer, the thing to do is to flag the question as duplicate. – Louis Jul 03 '16 at 20:59