I'm starting a React Native project, and I'd like to use ECMAScript 2015 for my code, and mocha for my unit tests. I've installed babel-register
, babel-preset-es2015
, and babel-preset-stage-2
, and added this to my project's package.json
file:
"babel": {
"presets": ["es2015", "stage-2"]
}
But when I run mocha --compilers js:babel-register
and try to test a module that imports a React Native API...
import React from 'react-native';
let {Dimensions} = React;
...I get an error about the spread operator used by React:
node_modules/react-native/Libraries/react-native/react-native.js:107
...require('React'),
^^^
SyntaxError: Unexpected token ...
Is this a babel bug—shouldn't the stage-2 preset add support for the spread operator? Or am I missing something else?
I just started seeing this too. Seems like a bug. AFAIK babel doesn't compile files under node_modules because they should always be precompiled.
Also this is a pretty recent addition
https://github.com/facebook/react-native/commit/f9b744d50137de25357994fe2e829f98104e2242
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With