我得到一个空白的浏览器,并且在控制台中出现此错误
未捕获的TypeError:超级表达式必须为null或a 功能,未定义
我看过其他类似的帖子,但没有发现任何相关内容。
这是我的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>
);
}
}
为清楚起见,我已经彻底检查了有关此错误的其他帖子,这是我的组件文件。
Editor.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);
Viewer.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);
答案 0 :(得分:1)
因此,在经过冗长的淘汰之后,我决定尝试从react
和react-dom
版本0.14.x
升级到15.4.0
,然后通过{{ 1}},现在就可以使用。