reactjs - webpack 对象 #<Object> 没有方法 'forEach'

标签 reactjs webpack babeljs

我将开始使用带有 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/

相关文章:

javascript - 当单击第二个或任何其他图像单选按钮时,第一个图像会更新

javascript - 古腾堡编辑器滚动 block 进入 View

javascript - Cx框架: How to set align:right and decimal precision on NumberField

laravel - Vite(在 Laravel 中)无法与公共(public)目录中的静态资源一起使用

reactjs - React Native - 找不到模块 X 或其相应的类型声明

javascript - 这是 .js 文件内的 Typescript 构造吗?我该如何处理?

reactjs - 使用 package.json react Bootstrap datepicker 问题

javascript - MiniCssExtractPlugin 没有创建 css 文件

javascript - 如何将所有 js 文件合并到一个 bundle webpack 中

javascript - Babel CLI --out-dir 在第二次编译时遇到权限错误