首页 > 解决方案 > creatreactapp & Reflux TypeError: Super expression must be null or a function

问题描述

我有一个简单的 createreactapp,我想用它来测试回流,而不是 redux,我正在尝试将 Reflux 包含在其中。我检查了 .Component 和 .Store 的拼写以及类结构,但仍然如此。

当我运行它时,它给了我这个错误:

TypeError:超级表达式必须为 null 或函数。

回流对于 createreactapp 来说太旧了吗?是 webpack 错误吗?通天塔?

完整错误:

inherits.js:4 Uncaught TypeError: Super expression must either be null or a 
function
    at _inherits (inherits.js:4)
    at statStore.js:7
    at Module../src/statStore.js (statStore.js:7)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/Compass.js (index.css:8)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?02e3:45)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Object.0 (statStore.js:42)
    at __webpack_require__ (bootstrap:782)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

stateStore.js

import React from 'react';
import actions from './actions';
import Reflux from 'reflux';



class statStore extends Reflux.Store {


    constructor(props){
        super(props);
        this.state = {
            status:0
        }
        this.listenables = actions;




    }


    onStateUpdate2(){

        this.setState({status:2})
        console.log('stateupdate2')
    }


    onStateUpdate3(){

        this.setState({status:3})
        console.log('stateupdate3')
    }




}


export default statStore;

指南针.js

import React from 'react';
import actions from './actions';
import statStore from './statStore';
import Reflux from 'reflux';


class Compass extends Reflux.Component {



    constructor(props){
        super(props);
        //this.store = statStore;
    }





    render(){


        console.log('BAHAHHA')

        return(<div onClick={actions.stateUpdate2}>{this.state.status}</div>)



    }



}


export default Compass;

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import Compass from './Compass';


ReactDOM.render(<Compass />, document.getElementById('root'));

标签: reactjsrefluxjs

解决方案


是的,我实际上从 createreactapp 中删除了 serviceWorker,这就是原因。


推荐阅读