Invalid configuration object. Webpack has been initialized using a configuration object that does no

Posted 闲言博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Invalid configuration object. Webpack has been initialized using a configuration object that does no相关的知识,希望对你有一定的参考价值。

错误产生环境

webpack 打包时出错

错误描述

Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[0] has an unknown property 'text'. These properties are valid:
   object  assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? 
   -> A rule description with conditions and effects for modules.

错误原因

配置webpack.config.js 文件时,节点名称输入错误。将test 输入为text标签

解决办法

修改前

const path = require('path')

const htmlWebpackPlugin = require('html-webpack-plugin')
const htmpPlugin = new HtmlWebpackPlugin(
  template: './src/index.html',
  filename: 'index.html'
)

module.exports = 
  //编译模式
  mode: 'development' // development  开发用(提高开发速度) | production
  ,
  //__dirname 代表当前文件所处的目录
  entry: path.join(__dirname,'./src/index.js'), //入口文件
  output: 
    path: path.join(__dirname,'./dist'),//输出文件存放路径
    filename: 'bundle.js'//输出文件名称
  ,
  devServer: 
    //....//
    static:                                
      directory: path.join(__dirname, './'),  
      watch: true
    
 ,// 配置预览界面插件
 plugins :[htmpPlugin],
 module : //配置打包非js的模块
   rules:[
     text: /\\.js$/,use: 'babel-loader',exclude: /node_modules/,
     test: /\\.css$/,use: ['style-loader','css-loader','postcss-loader'],
     test: /\\.less$/,use: ['style-loader','css-loader','less-loader'],
     test: /\\.scss$/,use: ['style-loader','css-loader','sass-loader']
    // test: /\\.jpg|png|gif|bmp|ttf|eot|svg|woff|woff2$/,use: ['url-loader?limit=98428']
    // test: /\\.jpg|png|gif|bmp|ttf|eot|svg|woff|woff2$/,use: 'url-loader?limit=98428'
  ]
 

修改后

const path = require('path')

const HtmlWebpackPlugin = require('html-webpack-plugin')
const htmpPlugin = new HtmlWebpackPlugin(
  template: './src/index.html',
  filename: 'index.html'
)

module.exports = 
  //编译模式
  mode: 'development' // development  开发用(提高开发速度) | production
  ,
  //__dirname 代表当前文件所处的目录
  entry: path.join(__dirname,'./src/index.js'), //入口文件
  output: 
    path: path.join(__dirname,'./dist'),//输出文件存放路径
    filename: 'bundle.js'//输出文件名称
  ,
  devServer: 
    //....//
    static:                                
      directory: path.join(__dirname, './'),  
      watch: true
    
 ,// 配置预览界面插件
 plugins :[htmpPlugin],
 module : //配置打包非js的模块
   rules:[
     text: /\\.js$/,use: 'babel-loader',exclude: /node_modules/,
     test: /\\.css$/,use: ['style-loader','css-loader','postcss-loader'],
     test: /\\.less$/,use: ['style-loader','css-loader','less-loader'],
     test: /\\.scss$/,use: ['style-loader','css-loader','sass-loader']
    // test: /\\.jpg|png|gif|bmp|ttf|eot|svg|woff|woff2$/,use: ['url-loader?limit=98428']
    // test: /\\.jpg|png|gif|bmp|ttf|eot|svg|woff|woff2$/,use: 'url-loader?limit=98428'
  ]
 

以上是关于Invalid configuration object. Webpack has been initialized using a configuration object that does no的主要内容,如果未能解决你的问题,请参考以下文章

Invalid configuration object. Webpack has been initialized using a configuration object that does no

Invalid configuration object. Webpack has been initialized using a configuration object that does no

webpack配置报错:invalid configuration object.webpack has been initialisted using a configuration objcet

解决办法:Invalid Gradle JDK configuration found

idea点击RUN启动报错: Broken configuration due to unavailable plugin or invalid configuration dat

SSH中的Invalid action class configuration that references an unknown class named.......