我正在使用ReactJS。

当我运行下面的代码时,浏览器会显示:

Uncaught TypeError:超级表达式必须为null或函数,不能为undefined

任何关于哪里出了问题的提示都会让我感激不尽。

首先是用来编译代码的行:

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的最新版本。

全球安装:

sudo npm install -g react@0.13.2

在本地安装:

npm install react@0.13.2

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

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

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


当前回答

在我的例子中,问题是因为将子类导入父类:

在子文件中:

class Child extends Parent {
   constructor();
}

在父文件中:

import Child from 'my_path';

class Parent {
   constructor();
}

问题解决后,我删除了子导入。

其他回答

在我的例子中,React <15.3.0不包括React. purecomponent。代码如下:

class MyClass extends React.PureComponent {
    //...
}

不工作。

当我的导入有一个错字时,我得到了这个:

import {Comonent} from 'react';

在我的例子中,使用react-native时,错误是我有

import React, {
  AppRegistry,
  Component,
  Text,
  View,
  TouchableHighlight
} from 'react-native';

而不是

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  AsyncStorage
} from 'react-native';

我的条件

Create-React-App React-scripts v3.2 Froala富文本编辑器v3.1 开发模式运行良好 产品构建因问题中提到的错误而中断

解决我问题的方法

将Froala降级到3.0版本。

3.1版中的某些内容破坏了我们的Create React应用程序构建过程。

更新:使用react脚本v3.3

我们发现在React Scripts 3.2和Froala 3.1之间有一个问题。

更新到React Scripts v3.3允许我们升级到Froala 3.1。

当我试图在父类和子类上使用react-i18next的翻译时,我得到了这个。它被翻译了两次!