3
votes

For some reason I'm getting Uncaught SyntaxError: Unexpected token (. No matter how simple the code is, I keep getting this error. There are similar questions but none solve this issue.

var Example = React.createClass({
  render: function() {
    return ( 
      <div>
        <h1> Hello </h1>
      </div>
    );
  }
});

ReactDOM.render( <Example/> , document.getElementById('example'));
<!DOCTYPE html>
<html>

<head>
  <script src="https://fb.me/react-0.14.2.js"></script>
  <script src="https://fb.me/react-dom-0.14.2.js"></script>
</head>

<body>
  <div id="example"></div>
</body>

</html>
1
I forgot to mention it says the syntax error is on line 1, which is render: function() - corasan
Your example works, given React environment: working demo - Amadan
What is with the extra whitespace? - epascarello
@epascarello I think it added the extra space when I used tidy. - corasan
@Amadan Yeah, it works on online editors. - corasan

1 Answers

2
votes

that is JSX syntax, you need to include the 'jsx transformer'. Base on Facebook's recommendation, you should use babeljs, https://babeljs.io/docs/usage/browser/