i am just starting with Reactjs and was writing a simple component to display li
tag and came across this error:
Unexpected token '<'
I have put the example at jsbin below http://jsbin.com/UWOquRA/1/edit?html,js,console,output
Please let me know what i am doing wrong.
In body ,where you connect your script , add type="text/jsx" and this`ll resolve the problem. Look at http://facebook.github.io/react/docs/getting-started.html and take note of the <script> tags, you need those included for JSX to work in the browser. Run this code from a single file and your it should work. Check if .
The JavaScript exceptions "unexpected token" occurs when a specific language construct was expected, but something else was provided. This might be a simple typo. Fortunately for developers, such errors are highlighted by the linters in code editors, so developers can fix it even before the app runs in the browser.
Not follow them throws an error.An unexpected token occurs if JavaScript code has a missing or extra character { like, ) + – var if-else var etc}. Unexpected token is similar to syntax error but more specific. Semicolon(;) in JavaScript plays a vital role while writing a programme.
I solved it using type = "text/babel"
<script src="js/reactjs/main.js" type = "text/babel"></script>
UPDATE: In React 0.12+, the JSX pragma is no longer necessary.
Make sure include the JSX pragma at the top of your files:
/** @jsx React.DOM */
Without this line, the jsx
binary and in-browser transformer will leave your files unchanged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With