我将开始使用带有 webpack 的 React with babel 但在运行 webpack -w
后它不起作用并显示类似的错误
TypeError: Object #<Object> has no method 'forEach'
我的 webpack 配置
module.exports = {
entry: "./app/components/Main.js",
output: {
filename: "public/bundle.js"
},
module: {
loaders: {
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader"
}
}
}
我的 Main.js react 文件
var React = require('react');
var Main = React.createClass({
render: function() {
return (
<div>
Hello world!
</div>
)
}
});
React.render(<Main />, document.getElementById('app'));
请问谁能解决这个问题吗?
最佳答案
我们应该为加载器对象指定一个加载器数组
module.exports = {
entry: "./app/components/Main.js",
output: {
filename: "public/bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loaders: ["babel-loader"],
}
],
},
};
关于reactjs - webpack 对象 #<Object> 没有方法 'forEach',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31218981/