webpack-contrib / mini-css-extract-plugin

Lightweight CSS extraction plugin
MIT License
4.67k stars 389 forks source link

Error with css-loader string export data #1044

Closed woody-li closed 10 months ago

woody-li commented 1 year ago

Bug report

When css-loader option exportType= 'string', it got error in file: https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/loader.js#L183

(!originalExports.default || !("locals" in originalExports.default));

Actual Behavior

Throw an error:

Module build failed
TypeError: Cannot use 'in' operator to search for 'locals' in xxxxxxx

Expected Behavior

Resolve the string data correctly.

How Do We Reproduce?

webpack config:

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const cssLoader = {
    loader: 'css-loader',
    options: {
        exportType: 'string',
    },
};
module.exports = {
    plugins: [new MiniCssExtractPlugin()],
    module: {
        rules: [
            {
                test: /\.css$/i,
                use: [MiniCssExtractPlugin.loader, cssLoader],
            },
        ],
    },
};

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: Windows 10 10.0.22621
    CPU: (8) x64 AMD EPYC 75F3 32-Core Processor
    Memory: 9.65 GB / 16.00 GB
  Binaries:
    Node: 18.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
  Packages:
    babel-loader: ^9.1.2 => 9.1.2
    css-loader: ^6.8.1 => 6.8.1
    less-loader: ^11.1.2 => 11.1.3
    terser-webpack-plugin: ^5.3.9 => 5.3.9
    webpack: ^5.88.1 => 5.88.1
alexander-akait commented 10 months ago

Because you should not to use exportType: 'string' with this plugin, it was design for other purposes I will update docs