reactjs给出错误Uncaught TypeError:超级表达式必须为null或函数,而不是未定义 [英] reactjs giving error Uncaught TypeError: Super expression must either be null or a function, not undefined

查看:2007
本文介绍了reactjs给出错误Uncaught TypeError:超级表达式必须为null或函数,而不是未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用reactjs。



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



未捕获类型错误:超级表达式必须为null或函数,而不是未定义



任何关于什么是错误的提示将不胜感激。 p>

首先用于编译代码的行:

  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> ;;
}
}

更新:
在地狱火燃烧后三天这个问题我发现我没有使用最新版本的反应。



全球安装

  sudo npm install -g reactions@0.13.2 

本地安装:

  npm install reactions@0.13.2 

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

 < script type =text / javascriptsrc =reactions-0.13.2.js>< / script> 

希望这可以为别人节省宝贵的生命三天。

解决方案

类名



首先,如果你确定你是从正确命名的类扩展,例如 React.Component ,不是React.component或React.createComponent,您可能需要升级您的React版本。



升级反应



React自版本0.13.0起才支持ES6风格的类(参见他们的官方博客文章,支持介绍 here



在此之前,使用时:

  class HelloMessage extends React.Component 
pre>

您尝试使用ES6关键字( extends )从未使用ES6 class 。这可能是为什么你用 super 定义等进行奇怪的行为。



所以,是的, TL; DR - 更新为React v0.13.x。



循环依赖关系



如果您有循环导入,也可能会发生结构体。一个模块导入另一个,而另一个模块。在这种情况下,您只需要重构代码以避免它。 rel = noreferrer>更多信息


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.

解决方案

Class Names

Firstly, if you're certain that you're extending from the correctly named class, e.g. React.Component, not React.component or React.createComponent, you may need to upgrade your React version. See answers below for more information on the classes to extend from.

Upgrade React

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.

Circular Dependencies

This can also occur if you have circular import structure. One module importing another and the other way around. In this case you just need to refactor your code to avoid it. More info

这篇关于reactjs给出错误Uncaught TypeError:超级表达式必须为null或函数,而不是未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆