Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactjs: Unexpected token '<' Error

Tags:

reactjs

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.

like image 723
sam Avatar asked Jan 03 '14 13:01

sam


People also ask

How do you solve the unexpected token in react?

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 .

What is unexpected token error in react?

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.

Why do I get unexpected token error?

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.


2 Answers

I solved it using type = "text/babel"

<script src="js/reactjs/main.js" type = "text/babel"></script> 
like image 175
Yuliia Ashomok Avatar answered Dec 09 '22 11:12

Yuliia Ashomok


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.

like image 39
Sophie Alpert Avatar answered Dec 09 '22 10:12

Sophie Alpert