Skip to content

Parse number for importLoaders in query parameter #1170

Closed
@cdoublev

Description

@cdoublev

Following your instructions given in this issue...

  • Operating System: Debian Buster
  • Node Version: 14.7.0
  • NPM Version: 6.14.7
  • webpack Version: 4.44.1
  • css-loader Version: 4.2.1

Expected Behavior / Situation

Run webpack with the following configuration, ie. containing an inline - string - definition of css-loader that contains number as value for importLoaders:

module.exports = {
    // ...
    module: { rules: [{
        test: /\.css$/,
        use: ['style-loader', 'css-loader?importLoaders=1', 'postcss-loader'],
    }] },
    // ...

Actual Behavior / Situation

Error thrown:

ValidationError: Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
 - options.importLoaders should be one of these:
   boolean | integer
   -> Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders).
   Details:
    * options.importLoaders should be a boolean.
    * options.importLoaders should be a integer.

Modification Proposal

"importLoaders": {

 // ...
         {
           "type": "integer"
+        },
+        {
+          "type": "string"
         }
       ]
     },
 // ...

importLoaders: rawOptions.importLoaders,

     : loaderContext.sourceMap,
-    importLoaders: rawOptions.importLoaders,
+   importLoaders: parseInt(rawOptions.importLoaders),
     esModule:
       typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule,
   };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions