configuration.module 有一个未知的属性 'loaders' [英] configuration.module has an unknown property 'loaders'

查看:24
本文介绍了configuration.module 有一个未知的属性 'loaders'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的错误输出:

无效的配置对象.Webpack 已使用与 API 架构不匹配的配置对象.- configuration.module 有一个未知的属性 'loaders'.这些属性是有效的: object { exprContextCritical?,exprContextRecursive?, exprContextRegExp?, exprContextRequest?,noParse?, rules?, defaultRules?, unknownContextCritical?,unknownContextRecursive?, unknownContextRegExp?,unknownContextRequest?、unsafeCache?、wrappedContextCritical?、wrapperContextRecursive?、wrappedContextRegExp?、strictExportPresence?,strictThisContextOnImports?} -> 选项影响正常模块(NormalModuleFactory).

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 { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? } -> Options affecting the normal modules (NormalModuleFactory).

我的 webpack.config.js:

my webpack.config.js:

var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');

var config = {
  entry: APP_DIR + '/index.jsx',
  module : {
    loaders : [
      {
        test : /\.jsx?/,
        include : APP_DIR,
        loader : 'babel-loader'
      }
    ]
  },
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  }

};


module.exports = config;

我的 webpack 版本:

my webpack version:

webpack@4.1.1

推荐答案

您应该在 webpack 4 中将 loaders 更改为 rules :

You should change loaders to rules in webpack 4:

改变:

loaders 

到:

rules

来源:加载程序

示例:

module.exports = {
  module: {
    rules: [
      { test: /\.css$/, use: 'css-loader' },
      { test: /\.ts$/, use: 'ts-loader' }
    ]
  }
};

这篇关于configuration.module 有一个未知的属性 'loaders'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆