我成功设置了te react开发设置。但是运行npm start会出现以下错误。
我无法弄清楚这个错误产生的位置。请帮助!
TypeError: Object #<Object> has no method 'forEach' at new LoadersList
(C:\Users\User\AppData\Roaming\npm\node_modules\webpack\node_modules\webpack-
core\lib\LoadersList.js:7:12) at new NormalModuleFactory (C:\Users
\User\AppData\Roaming\npm\node_modules\webpack
\lib\NormalModuleFactory.js:16:17) at Compiler.createNormalModuleFactory
(C:\Users\User\AppData\Roaming\npm\node_modules\webpack
\lib\Compiler.js:369:28) at Compiler.newCompilationParams (C:\Users
\User\AppData\Roaming\npm\node_modules\webpack\lib\Compiler.js:382:29) at
Compiler.compile (C:\Users\User\AppData\Roaming\npm\node_modules\webpack
\lib\Compiler.js:389:20) at Watching.<anonymous> (C:\Users\User\AppData
\Roaming\npm\node_modules\webpack\lib\Compiler.js:46:17) at Compiler.next
(C:\Users\User\AppData\Roaming\npm\node_modules\webpack\node_modules\tapable
\lib\Tapable.js:67:11) at Compiler.invalidAsyncPlugin (C:\Users\User\AppData
\Roaming\npm\node_modules\webpack-dev-server\node_modules\webpack-
dev-middleware\middleware.js:80:3) at Compiler.applyPluginsAsync (C:\Users
\User\AppData\Roaming\npm\node_modules\webpack\node_modules\tapable
\lib\Tapable.js:71:13) at Watching._go (C:\Users\User\AppData\Roaming
\npm\node_modules\webpack\lib\Compiler.js:44:16)
请建议。谢谢!
答案 0 :(得分:0)
Object #<Object> has no method 'forEach'
forEach will work for Array, means looping the array,
but in your case your calling the method `forEach` in Object.
正确:
[].forEach.
你正在做的是:
{}.forEach
答案 1 :(得分:0)
如果有人面临同样的问题,原因是因为webpack.config.js中的加载器是一个对象而不是对象值数组。
即。所有加载器必须包装在一个数组中。作为对象数组。
module:{
loaders:**[**
{
test:/\.jsx?$/,
exclude:/node_modules/,
loader:'babel',
query:{
presets:['react','es2015']
}
}
**]**
}