webpack-contrib / sass-loader

Compiles Sass to CSS
MIT License
3.91k stars 431 forks source link

Asset module source map `sources` are invalid and omit `sourcesContent` #1222

Closed colinrotherham closed 3 months ago

colinrotherham commented 3 months ago

Bug report

When using the new webpack@5.93.0 binary generator option (see issue #962) the source map JSON is missing sourcesContent and has invalid webpack:///data:; content inside the sources array.

This also affects previous releases using modern or modern-compiler API option too.

Note: Unlike the legacy compiler, missing sourcesContent can be restored with ~sourceMapContents: true~ sourceMapIncludeSources: true but the sources property remains invalid.

Actual Behavior

Source map sourcesContent is missing and sources content includes encoded content

- {"version":3,"sourceRoot":"","sources":["webpack:///../node_modules/govuk-frontend/dist/govuk/core/_govuk-frontend-properties.scss",
+ {"version":3,"sourceRoot":"","sources":["webpack:///data:;charset=utf-8,:root%20%7B%0A%20%20//

In Safari web inspector, this is logged with Failed to load resource: unsupported URL

Expected Behavior

Source map sourcesContent is included by default and sources content is correctly encoded

How Do We Reproduce?

See minimal reproduction repo in colinrotherham/sass-loader-source-maps

This follows the README asset module approach via the following rule:

{
  test: /\.scss$/,
  type: 'asset/resource',
  generator: {
    binary: false,
    filename: '[name].css[query]'
  },
  use: [
    {
      loader: 'sass-loader',
      options: {
        // api: 'legacy', // ✅
        // api: 'modern', // ❌
        // api: 'modern-compiler', // ❌
        sassOptions: {
          quietDeps: true,
          style: 'expanded'
        }
      }
    }
  ]
}

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

  System:
    OS: macOS 14.5
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
    Memory: 565.87 MB / 32.00 GB
  Binaries:
    Node: 20.11.0 - ~/.asdf/installs/nodejs/20.11.0/bin/node
    Yarn: 1.22.22 - ~/.asdf/installs/nodejs/20.11.0/bin/yarn
    npm: 10.2.4 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 126.0.6478.183
    Safari: 17.5
  Packages:
    sass-loader: ^16.0.0 => 16.0.0
    webpack: ^5.93.0 => 5.93.0
    webpack-cli: ^5.1.4 => 5.1.4
alexander-akait commented 3 months ago

hm, I think the bug in webpack, maybe we don't have data: protocol properly, I will look deeply