gpt4 book ai didi

reactjs - webpack 对象 # 没有方法 'forEach'
转载 作者:行者123 更新时间:2023-12-03 14:04:45 25 4
gpt4 key购买 nike

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

25 4 0