gpt4 book ai didi

javascript - React-Redux 与 webpack 给出错误 Uncaught TypeError : Super expression must either be null or a function, not undefined

转载 作者:行者123 更新时间:2023-12-03 01:05:20 25 4
gpt4 key购买 nike

我得到一个空白浏览器,在控制台中我收到此错误

Uncaught TypeError: Super expression must either be null or a function, not undefined

我读过其他类似的帖子,但没有看到任何相关内容。

这是我的 webpack.config.js 文件:

const path = require('path');

module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel'
}]
},
resolve: {
root: path.resolve(__dirname, 'src'),
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};

这是我的package.json 文件:

{
"name": "JSFaddle",
"version": "1.0.0",
"description": "",
"main": "index.js",
"repository": "git@github.com:ldco2016/JSFaddle.git",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"jquery": "^2.2.1",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"babel-standalone": "^6.7.7",
"esprima": "^2.7.2",
"lodash": "^3.10.1",
"react": "^0.14.3",
"react-addons-create-fragment": "^15.1.0",
"react-codemirror": "^0.2.6",
"react-dom": "^0.14.3",
"react-redux": "^4.0.0",
"react-router": "^2.0.1",
"react-split-pane": "^0.1.42",
"redux": "^3.0.4",
"reselect": "^2.5.1"
}
}

这是src/index.js文件:

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';

import App from './components/app';
import reducers from './reducers';
import Globals from './globals';

const createStoreWithMiddleware = applyMiddleware()(createStore);

ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>
, document.querySelector('.render'));

您已经注意到我正在运行一些旧版本的 webpack 和其他软件包,因为我试图加快使用 Webpack 的速度,但我不确定这是否是问题所在。我不确定它的引用是什么。

有人问我有关扩展的问题,我在 src/components/App.js 中这样做:

import React, { Component } from 'react';
import SplitPane from 'react-split-pane';
import Editor from './editor';
import Viewer from './viewer';

export default class App extends Component {
render() {
const width = window.innerHeight;

return (
<SplitPane split="vertical" defaultSize={width}>
<Editor />
<Viewer />
</SplitPane>
);
}
}

需要明确的是,我已经彻底查看了有关此错误的其他帖子,这是我的组件文件。

编辑器.js:

import _ from 'lodash';
import React, { Component } from 'react';
import CodeMirror from 'react-codemirror';
import 'codemirror/mode/jsx/jsx';
import * as actions from 'actions';
import { connect } from 'react-redux';

class Editor extends Component {
onCodeChange(code) {
this.props.updateCode(code);
}

render() {
return (
<div>
<CodeMirror
value={this.props.code}
onChange={this.onCodeChange.bind(this)}
options={{ mode: 'jsx', lineNumbers: true, tabSize: 2 }} />
</div>
);
}
}

function mapStateToProps({code}) {
return { code };
}

export default connect(mapStateToProps, actions)(Editor);

查看器.js:

import _ from 'lodash';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import parseExpressions from 'selectors/parse_expressions';
import SplitPane from 'react-split-pane';

class Viewer extends Component {
evaluateExpressions(expressions) {
const formattedExpressions = _.mapValues(expressions, expression => {
const result = eval(expression);

if (result && result.type) {
return result;
} else if (_.isFunction(result) && result.name) {
return <i>Function {result.name}</i>;
} else if (_.isBoolean(result)) {
return result ? 'True' : 'False';
} else if (_.isObject(result) || _.isArray(result)) {
return JSON.stringify(result);
}

return result;
});

return _.map(formattedExpressions, (expression, line) =>
<div>{expression}</div>
);
}

renderExpressions(code) {
return this.evaluateExpressions(this.props.expressions);
}

render() {
const defaultHeight = window.innerHeight / 1.3;

return (
<SplitPane split="horizontal" defaultSize={defaultHeight} className="viewer">
<div className="result">
{this.renderExpressions(this.props.code)}
</div>
<div className="errors">
{this.props.errors}
</div>
</SplitPane>
);
}
}

function mapStateToProps(state){
let expressions, errors;

try {
expressions = parseExpressions(state);
} catch (e) {
errors = e.toString();
}

return { expressions, errors };
}

export default connect(mapStateToProps)(Viewer);

最佳答案

因此,经过漫长的排除过程后,我决定尝试从 reactreact-dom 版本 0.14.x 升级到15.4.0,我通过 npm start 重新启动了应用程序,它现在可以工作了。

关于javascript - React-Redux 与 webpack 给出错误 Uncaught TypeError : Super expression must either be null or a function, not undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52435164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com