版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/m0_37750720/article/details/82940433
错误信息如下:
E:\works\ES6>gulp
[20:37:23] Failed to load external module @babel/register
[20:37:23] Requiring external module babel-register
[20:37:26] Using gulpfile E:\works\ES6\gulpfile.babel.js
[20:37:26] Starting 'build'...
[20:37:26] Starting 'clean'...
[20:37:26] Finished 'clean' after 97 ms
[20:37:26] Starting 'css'...
[20:37:26] Finished 'css' after 39 ms
[20:37:26] Starting 'pages'... [20:37:26] Finished 'pages' after 24 ms
[20:37:26] Starting 'scripts'...
E:\works\ES6\node_modules\webpack\lib\webpack.js:31
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
^
WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.module has an unknown property 'loaders'. These properties are valid:
object { defaultRules?, exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, strictExportPresence?, strictThisContextOnImports?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? }
-> Options affecting the normal modules (`NormalModuleFactory`).
at webpack (E:\works\ES6\node_modules\webpack\lib\webpack.js:31:9) at Stream.<anonymous> (E:\works\ES6\node_modules\webpack-stream\index.js:148:38)
at _end (E:\works\ES6\node_modules\through\index.js:65:9)
at Stream.stream.end (E:\works\ES6\node_modules\through\index.js:74:5)
at Stream.onend (internal/streams/legacy.js:44:10)
at emitNone (events.js:111:20) at Stream.emit (events.js:208:7)
at drain (E:\works\ES6\node_modules\through\index.js:34:23)
at Stream.stream.queue.stream.push (E:\works\ES6\node_modules\through\index.js:45:5)
at Stream.end (E:\works\ES6\node_modules\through\index.js:15:35)
配置代码如下:
.pipe(gulpWebpack({
module:{
loaders:[{
test:/\.js$/,
loader:'babel'
}]
}
}),null,(err,stats)=>{
log(`Finished '${colors.cyan('scripts')}'`,stats.toString({
chunks:false
}))
})
百度觅得解决办法:
点此传送 -> 新手运行webpack 报错: unknown property ‘loaders’.
- 直接将原来的loaders改为rules就可以了!
- 原因是webpack不同的版本有不同的写法…