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

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


当前回答

在我的例子中,我使用了一个具有对等依赖关系的npm模块。该错误是由模块的webpack配置中错误的“外部”配置引起的:

  externals: {
    react: 'react',
    react: 'prop-types',
  },

它应该是:

externals: {
    react: 'react',
    ['prop-types']: 'prop-types',
  },

其他回答

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

如果您在导入或类生成中有拼写错误,可能只是这样。

我在导入组件时遇到了这个错误,比如:

import React, { Components } from 'react';

而不是

import React, { Component } from 'react';

问题似乎是这样的 反应。组件而不是React.Component。

还有,ReactDOM是你写的吗?render(, YourNode) here?

希望你的问题解决了。干杯!

组件名称可能存在拼写/大小写错误: 例如:

class HelloMessage extends React.Component

class HelloMessage extends React.component

请查一下。