Skip to content

new URL('./style.scss', import.meta.url) generates style.css and style.scss, empty #1146

@fregante

Description

@fregante

Bug Description

I can't use the alternative to resourceQueries described by https://webpack.js.org/guides/asset-modules/#url-assets

The problem might be wanting to have 3 things at once:

  • raw imports like import "./style.css" -> extracted by mini-css-extract-plugin
  • CSS modules -> also extracted
  • asset imports like new URL("./style.css", import.meta.url) parsed as CSS before being extracted

Link to Minimal Reproduction and step to reproduce

Full repro: https://github.com/fregante/webpack-sandbox/tree/main/new-url-scss

const newUrl = new URL("bootstrap/scss/bootstrap.scss", import.meta.url);

console.log("?url", URL);
import MiniCssExtractPlugin from "mini-css-extract-plugin";

const config = {
  mode: "development",
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader",
          "sass-loader"
        ],
      },
    ],
  },
  plugins: [new MiniCssExtractPlugin()],
};

export default config;

Expected Behavior

The file should be handled by the S/CSS loaders and appear in dist

Actual Behavior

The file contains:

// extracted by mini-css-extract-plugin
export {};

And actually I see it duplicated, as .css and .scss

Environment

System:
    OS: macOS 15.6.1
  Binaries:
    Node: 22.18.0 - /usr/local/bin/node
    npm: 10.9.3 - ~/.bun/bin/npm
  Browsers:
    Chrome: 141.0.7390.108
    Safari: 18.6
  Packages:
    css-loader: ^7.1.2 => 7.1.2 
    sass-loader: ^16.0.5 => 16.0.5 
    style-loader: ^4.0.0 => 4.0.0 
    webpack: ^5.102.1 => 5.102.1 
    webpack-cli: ^6.0.1 => 6.0.1

Is this a regression?

No

Last Working Version

No response

Additional Context

No response

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