4

I keep getting an error SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

I think it is because I have a line like this:

    const shouldSet = touches.length === 1;
    if (shouldSet) {
      const { onPanBegin } = this.props;
Adrienne
  • 2,540
  • 1
  • 29
  • 39
  • 1
    this might be useful http://stackoverflow.com/questions/22603078/syntaxerror-use-of-const-in-strict-mode – knowbody Jul 31 '15 at 16:11

3 Answers3

3

Update 2015-10-23: as of React Native v0.13.0-rc const is now enabled.

React Native's JavaScript environment is not a browser, instead it uses JavaScriptCore. Anything that isn't supported natively needs to be transformed down to a subset of JS that JavaScriptCore supports, and React Native uses Babel to do that. Here are the transformations that React Native uses (as of 2015-07-31):

ES5

  • Reserved Words: promise.catch(function() { });

ES6

  • Arrow functions
  • Call spread
  • Classes
  • Destructuring
  • Computed Properties
  • Object Consise Method
  • Object Short Notation
  • Rest Params
  • Template Literals:

ES7

  • Object Spread
  • Function Trailing Comma

It is not immediately clear to me why constants aren't included in this list, and it appears that support for overriding it still isn't quite ready:

https://github.com/facebook/react-native/issues/1451

Colin Ramsay
  • 16,086
  • 9
  • 52
  • 57
0

At the moment const keyword is not supported in react-native android, I hope it will be available with the next release of react-native. The fix was trivial, for more details look into origin github issue.

Yevgen Safronov
  • 3,977
  • 1
  • 27
  • 38
0

you need get the lastest version of react-native.

pod 'React', '0.13.0-rc'

deju
  • 1,028
  • 2
  • 10
  • 16