无法读取未定义的 extract-text-webpack-plugin 的属性“查询”

2024-04-14

我正在尝试使用 webpack 2 实现 extract-text-webpack-plugin 并且我正在从头开始构建我的 webpack.config.js 。当我想添加插件时,我按照以下说明进行操作npm https://www.npmjs.com/package/extract-text-webpack-plugin。然而,这给了我以下错误:

TypeError: Cannot read property 'query' of undefined

我环顾四周,没有发现其他人对这个插件有同样的问题。在假设这是一个错误之前,我宁愿先问我是否犯了一个错误。

我的 webpack.config.js 是

const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
  context: path.resolve(__dirname, './src'),
  entry: {
    app: './main.js',
  },
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: '[name].bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: [/node_modules/],
        use: [{
          loader: 'babel-loader',
          options: { presets: ['es2015'] }
        }]
      },
      {
        test: /\.(sass|scss)$/,
        use: [
          'style-loader',
          'css-loader',
          'sass-loader',
        ]
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader"
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin("styles.css"),
  ],
};

完整的错误是

/node_modules/extract-text-webpack-plugin/index.js:134
    if(!loader.query) return loader.loader;
              ^

TypeError: Cannot read property 'query' of undefined
    at getLoaderWithQuery (/node_modules/extract-text-webpack-plugin/index.js:134:12)
    at Array.map (native)
    at Function.ExtractTextPlugin.extract (/node_modules/extract-text-webpack-plugin/index.js:201:4)
    at Object.<anonymous> (/webpack.config.js:33:32)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)

您正在使用过时的版本extract-text-webpack-plugin,这已在第一个候选版本之前被删除v2.0.0。您可能有测试版。

安装最新版本:

npm install --save-dev extract-text-webpack-plugin@latest

Or with Yarn https://github.com/yarnpkg/yarn你可以运行:

yarn upgrade extract-text-webpack-plugin
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法读取未定义的 extract-text-webpack-plugin 的属性“查询” 的相关文章

随机推荐