本文介绍了ReactJS 给出错误 Uncaught TypeError: Super expression must be null or a function, not undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用 ReactJS.

I am using ReactJS.

当我运行浏览器下面的代码时说:

When I run the code below the browser says:

未捕获的类型错误:超级表达式必须为空或函数,不能为未定义

如有任何错误提示,我们将不胜感激.

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

和代码:

var React = require('react');

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

更新:在这个问题上在地狱火中燃烧了三天后,我发现我没有使用最新版本的 react.

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

全局安装:

sudo npm install -g [email protected]

本地安装:

npm install [email protected]

确保浏览器也使用正确的版本:

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

希望这能挽救别人三天宝贵的生命.

Hope this saves someone else three days of precious life.

推荐答案

也可能是拼写错误造成的,所以用大写 C 代替 Component ,而是 component代码>与较低的c,例如:

It can also be caused by a typo error, so instead of Component with capital C, you have component with lower c, for example:

React.component //wrong.
React.Component //correct.

注意:这个错误的根源可能是因为有React,我们自动认为接下来应该是一个以小写字母开头的react方法或属性,但实际上它是另一个Class(Component) 应该以大写字母开头.

Note:The source of this error is may be because there is React and we think automatically what comes next should be a react method or property starting with a lowercase letter, but in fact it is another Class(Component) which should start with a capital case letter.

这篇关于ReactJS 给出错误 Uncaught TypeError: Super expression must be null or a function, not undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:50