webpack-contrib / sass-loader

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

sass-embedded and morder-compiler api not working with resolve-url-loader, error expected "base" to be absolute path to a vaild directory #1217

Closed JiangWeixian closed 4 months ago

JiangWeixian commented 4 months ago

Bug report

switch sass to sass-embedded with follow sass-loader options

sourceMap: true,
sassOptions: {
  quietDeps: true,
  // Only allowed to ignore warnings from node_modules
  silenceDeprecations: ['slash-div'],
  logger: Logger.silent,
},
implementation: require('sass-embedded'),
api: 'modern-compiler',

meat problem:

image

find as similar issue in sass repo: https://github.com/sass/sass/issues/3300

Actual Behavior

compile failed

Expected Behavior

compile successful, should work fine as same as when implementation is sass

How Do We Reproduce?

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

System:
    OS: macOS 14.1.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 140.31 MB / 64.00 GB
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
  Browsers:
    Chrome: 126.0.6478.183
    Edge: 126.0.2592.113
    Safari: 17.1
JiangWeixian commented 4 months ago

according to https://github.com/sass/sass/issues/3300, it works fine when add sourceMapUrl in load function return. Not sure it's a bug...

const contents = await new Promise((resolve, reject) => {
  // Old version of `enhanced-resolve` supports only path as a string
  // TODO simplify in the next major release and pass URL
  const canonicalPath = _url.default.fileURLToPath(canonicalUrl);
  loaderContext.fs.readFile(canonicalPath, "utf8", (err, content) => {
    if (err) {
      reject(err);
      return;
    }
    resolve(content);
  });
});
return {
  contents,
  syntax,
+  sourceMapUrl: canonicalUrl,
};
alexander-akait commented 4 months ago

Sorry not related to sass-loader please open an issue in resolve-url-loader, we always return absolute urls, maybe you have source maps comment in your CSS libraries

If you provide reproducible test repo I can show you there is a bug