Javascript React应用程序已编译,但控制台中存在错误
我刚刚开始用webpack构建React.js应用程序,虽然代码编译得很好,但我得到了:Javascript React应用程序已编译,但控制台中存在错误,javascript,reactjs,webpack,babeljs,Javascript,Reactjs,Webpack,Babeljs,我刚刚开始用webpack构建React.js应用程序,虽然代码编译得很好,但我得到了: Uncaught TypeError: Cannot read property 'array' of undefined at Object.<anonymous> (RoutingContext.js:28) 我认为导致问题的代码是: render(( <Router history={hashHistory}> <Route path="/" compone
Uncaught TypeError: Cannot read property 'array' of undefined
at Object.<anonymous> (RoutingContext.js:28)
我认为导致问题的代码是:
render((
<Router history={hashHistory}>
<Route path="/" component={App}>
<Route path="adverts" name="adverts" component={Adverts}></Route>
<Route path="ads" name="ads" component={Adverts}></Route>
</Route>
</Router>
), document.getElementById('root'));
在应用程序中使用react 16时,您可能正在使用旧版本的react路由器,其对等依赖项为react 15。React从主包中删除了16个PropTypes,看起来React路由器正在期待它。更新react router。您可以添加有关该问题的更多详细信息吗?从样本中不清楚问题出在哪里is@ThisIzKp我将添加我的webpack配置,但我不知道问题出在哪里,但为什么您认为webpack配置可能是问题?@ThisIzKp错误在lib中您是否安装了道具类型?
render((
<Router history={hashHistory}>
<Route path="/" component={App}>
<Route path="adverts" name="adverts" component={Adverts}></Route>
<Route path="ads" name="ads" component={Adverts}></Route>
</Route>
</Router>
), document.getElementById('root'));
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: path.join(__dirname, "src"),
devtool: debug ? "inline-sourcemap" : null,
entry: ["babel-polyfill", "./index.js"],
module: {
rules: [
{ test: /\.json$/, loader: 'json-loader' }
],
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
}
},
{
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader'],
}
]
},
output: {
path: __dirname + "/src/",
filename: "index.min.js"
},
plugins: debug ? [] : [
new webpack.IgnorePlugin(/(locale)/, /node_modules.+(momentjs)/),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
};