Duke Dougal Duke Dougal - 3 months ago 125
React JSX Question

reactjs giving error Uncaught TypeError: Super expression must either be null or a function, not undefined

I am using reactjs.

When I run the code below the browser says:

Uncaught TypeError: Super expression must either be null or a function, not undefined

Any hints at all as to what is wrong would be appreciated.

First the line used to compile the code:

browserify -t reactify -t babelify examples/temp.jsx -o examples/public/app.js


And the code:

var React = require('react');

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


UPDATE:
After burning in hellfire for three days on this problem I found that I was not using the latest version of react.

Install globally:

sudo npm install -g react@0.13.2


install locally:

npm install react@0.13.2


make sure the browser is using the right version too:

<script type="text/javascript" src="react-0.13.2.js"></script>


Hope this saves someone else three days of precious life.

Answer

The fix of upgrading React has been added to the question by OP, but some explanation: React has only supported ES6-style classes since version 0.13.0 (see their official blog post on the support introduction here.

Before that, when using:

class HelloMessage extends React.Component

you were attempting to use ES6 keywords (extends) to subclass from a class which wasn't defined using ES6 class. This was likely why you were running into strange behaviour with super definitions etc.

So, yes, TL;DR - update to React v0.13.x.

Comments