我将开始使用与网络包的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反应文件
var React = require('react');
var Main = React.createClass({
render: function() {
return (
<div>
Hello world!
</div>
)
}
});
React.render(<Main />, document.getElementById('app'));
请有人解决此问题吗?
答案 0 :(得分:5)
我们应该为加载器对象指定一个加载器数组
module.exports = {
entry: "./app/components/Main.js",
output: {
filename: "public/bundle.js"
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loaders: ["babel-loader"],
}
],
},
};