Search code examples
react-nativeecmascript-next

Using ES7 static propTypes with React-Native


When I'm launching my project using React-Native default packager, I have this error: Unexpected token on this line:

static propTypes = {
   /// ...
};

I took a look on React-Native issues on GitHub, but I didn't find a solution.

Any suggestion?


Solution

  • After @Fomahaut answer, I keep looking on Facebook's GitHub repository and found this issue: https://github.com/facebook/react-native/issues/2182

    • Create a .babelrc file at the project's root directory
    • Add more rules to Babel

    Example:

        {
          "retainLines": true,
          "compact": true,
          "comments": false,
          "whitelist": [
            "es6.arrowFunctions",
            "es6.blockScoping",
            "es6.classes",
            "es6.constants",
            "es6.destructuring",
            "es6.forOf",
            "es6.modules",
            "es6.parameters",
            "es6.properties.computed",
            "es6.properties.shorthand",
            "es6.spread",
            "es6.tailCall",
            "es6.templateLiterals",
            "es6.regex.unicode",
            "es6.regex.sticky",
            "es7.asyncFunctions",
            "es7.classProperties",
            "es7.comprehensions",
            "es7.decorators",
            "es7.exponentiationOperator",
            "es7.exportExtensions",
            "es7.functionBind",
            "es7.objectRestSpread",
            "es7.trailingFunctionCommas",
            "regenerator",
            "flow",
            "react",
            "react.displayName"
            ],
          "sourceMaps": false
        }