Skip to content

Failed to extacrt source with @import external resources and source mapping #1215

@OpportunityLiu

Description

@OpportunityLiu
  • Operating System: Windows 10 1904
  • Node Version: v12.18.1
  • NPM Version: 6.14.5
  • webpack Version: 5.1.3
  • css-loader Version: 5.0.0

Expected Behavior

Build with no error.

Actual Behavior

ERROR in ./src/components/elements/icon.scss?module
Module build failed (from ./node_modules/extract-loader/lib/extractLoader.js):
TypeError: Cannot read property 'sources' of undefined
    at cssWithMappingToString (node_modules\css-loader\dist\runtime\cssWithMappingToString.js:26:33)
    at node_modules\css-loader\dist\runtime\api.js:14:21
    at Array.map (<anonymous>)
    at Array.toString (node_modules\css-loader\dist\runtime\api.js:13:17)
    at extractExports (node_modules\extract-loader\lib\extractLoader.js:182:269)
    at node_modules\extract-loader\lib\extractLoader.js:171:45
    at Generator.next (<anonymous>)
    at step (node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30)
    at babel-runtime\helpers\asyncToGenerator.js:28:13

Code

// webpack.config.js
// If your code blocks are over 20 lines, please paste a link to a gist
// (https://gist.github.com).
module.exports = (env = {}, argv = {}) => {
  const config = {
    target: "web",
    entry: "./index.js",
    module: {
      rules: [
        {
          test: /\.css$/i,
          use: [
            "file-loader",
            "extract-loader",
            {
              loader: "css-loader",
              options: {
                importLoaders: 1,
              },
            },
            {
              loader: "postcss-loader",
              options: {
                postcssOptions: { plugins: ["postcss-preset-env"] },
              },
            },
          ],
        },
      ],
    },
    devtool: 'inline-source-map'
  };

  return config;
};
@import url('https://cdn.bootcss.com/material-design-icons/3.0.2/iconfont/material-icons.css');

span {
  font-family: 'Material Icons';
}

How Do We Reproduce?

git clone https://github.com/OpportunityLiu/css-extract-with-url
yarn
yarn build

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