3

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>

8
  • I forgot to mention it says the syntax error is on line 1, which is render: function() Commented Nov 16, 2015 at 1:17
  • Your example works, given React environment: working demo Commented Nov 16, 2015 at 1:26
  • 2
    What is with the extra whitespace? Commented Nov 16, 2015 at 1:26
  • @epascarello I think it added the extra space when I used tidy. Commented Nov 16, 2015 at 1:50
  • @Amadan Yeah, it works on online editors. Commented Nov 16, 2015 at 1:50

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

6 Comments

I found the problem. I had an atom package that was compiling my jsx file to js. Thank you for the help
What package was that?
@corasan it's no longer available
@Kalanamith what is no longer available?
@corasan the link you have provided in the answer . please update
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.