Sign in
Log inSign up

Uncaught SyntaxError: Unexpected token < in React

Ankur Singh's photo
Ankur Singh
·Feb 23, 2019

I have created an index.html, which is like:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>React Example</title>
        <script crossorigin="anonymous" src="unpkg.com/react@16/umd/react.development.js"></script>
        <script crossorigin="anonymous" src="unpkg.com/react-dom@16/umd/react-dom.devel…"></script>
        <script type="text/babel" src="unpkg.com/babel-standalone@6/babel.min.js"></script>
        <script type="text/javascript" src="myScript.js"></script>
    </head>
    <body>
        <div id="root"></div>
        <script type="text/babel">
            ReactDOM.render(<MyTag />, document.getElementById("root"));
        </script>
    </body>
</html>

And my react (myScript.js) file is like:

class MyTag extends React.Component {
    render() {
        return <h1>Hello</h1>;
    }
}

Now, I tried to run this code it gives me error, Uncaught SyntaxError: Unexpected token < at the line of return <h1>Hello</h1>;

How I can solve this problem?