webpack对象#<object>没有方法&#39; forEach&#39;

时间:2015-07-04 09:15:39

标签: reactjs webpack babeljs

我将开始使用与网络包的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'));

请有人解决此问题吗?

1 个答案:

答案 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"],
            }
      ],
    },

};