Css-loader: TypeError: text.forEach is not a function

Created on 27 Aug 2020  路  3Comments  路  Source: webpack-contrib/css-loader

I'm trying to update css-loader from 3.6.0 to 4.2.2. My previous configuration was like this:

{
        test: /\.css$/,
        exclude: [/node_modules/, /other.css/],
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                modules: true,
                importLoaders: 1,
                localsConvention: 'camelCase',
              },
            },
            'postcss-loader',
           ],
}

With the update of the library I start to got the error that localsConvention wasn't a possible option. So following the documentation I changed my options to this:

{
        test: /\.css$/,
        exclude: [/node_modules/, /other.css/],
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                modules: {
                  compileType: 'module',
                  mode: 'local',
                  auto: true,
                  exportGlobals: true,
                  namedExport: true,
                  exportLocalsConvention: 'camelCaseOnly',
                  exportOnlyLocals: true,
                },
                importLoaders: 1,
              },
            },
            'postcss-loader',
          ],
        }

And I started to have this error:

Capture

What am I doing wrong?

Most helpful comment

It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I'm closing this. Please either update the issue with the template and reopen, or open a new issue.

ExtractTextPlugin was deprecated, please migrate on mini-css-extract-plugin

All 3 comments

It looks like you just deleted our lovely crafted issue template. It was there for good reasons. Please help us solving your issue by answering the questions asked in this template. I'm closing this. Please either update the issue with the template and reopen, or open a new issue.

ExtractTextPlugin was deprecated, please migrate on mini-css-extract-plugin

I confirm the problem was the deprecated library!

Thank you very much for the fast answer and sorry I deleted the template 馃檹

Thanks!

Migrated from:
plugins: [new ExtractTextPlugin('[name].[chunkhash].css')]

{
  ...
  use: ExtractTextPlugin.extract({
    use: ['css-loader', 'postcss-loader', 'sass-loader'],
    fallback: 'style-loader',
  }),
  ...
}

to

plugins: new MiniCssExtractPlugin({ filename: '[name].[chunkhash].css' }),

{
  ...
  use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
  ...
}

And now it works with 4.2.2

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tapz picture tapz  路  3Comments

jonathanong picture jonathanong  路  3Comments

mareksuscak picture mareksuscak  路  5Comments

fengyun2 picture fengyun2  路  4Comments

kcjonson picture kcjonson  路  3Comments