我正在使用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>

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


当前回答

在我的例子中,使用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';

其他回答

我有这个问题,因为我的react和react-dom版本在合并后不匹配。

我手动输入我想要的版本号并重新运行npm install来修复它。

我写

React.component

而不是React。组件 这是我的问题)) 为了这个找了半个多小时。

这个答案不正确,但对于其他有同样错误的人,我这个愚蠢的错误可能会有帮助。

愚蠢的是,我的问题是通过在类名后面包含()来使用函数符号。

确保语法正确。并且您已经导入和导出了所有具有正确名称和路径的外部组件/模块。

如果你安装了一个新版本的react,这个模板应该可以正常工作:

import React, { Component } from 'react'

class ExampleClass extends Component {

    render(){
        return(
            <div>

            </div>
        )
    }
}

export default ExampleClass 

Expo/react-native与typescript的另一种情况是:有时当你在打包过程中重新编译typescript文件时,react打包器会丢失。

让我的应用程序再次运行的唯一方法是清除缓存;如果你使用的是世博命令行,你可以按下R(大写的“R”);这将重新构建整个包。有时切换到开发模式也有帮助....

如果在代码中使用require而不是import,也会发生这种情况。