webpack-contrib / sass-loader

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

Sass loader fails with a particular additionalData #1249

Closed minimit closed 4 days ago

minimit commented 5 days ago

Bug report

Actual Behavior

With this options:

const rootDir = path.join(__dirname, '.build')

{
  loader: 'sass-loader',
  options: {
    additionalData: `$rootDir: ${rootDir};`,
  },
},

Webpack fails with this error:

ERROR in ./src/test.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[0].use[2]!./src/test.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
Expected digit.
  ╷
1 │ $rootDir: /Users/riccardocaroli/Documents/Apache/www/_libraries/webpack-sass-loader-bug/.build;
  │                                                                                          ^
  ╵
  src/test.scss 1:90  root stylesheet
 @ ./src/test.scss 8:6-167 20:17-24 24:0-137 24:0-137 25:22-29 25:33-47 25:50-64
 @ ./src/app.js 1:0-20

Expected Behavior

Webpack should compile and not give error, if you use const rootDir = path.join(__dirname, 'build') without the dot it works.

How Do We Reproduce?

Minimal reproduction here https://github.com/webgriffe/webpack-sass-loader-bug

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

alexander-akait commented 4 days ago

$rootDir: ${rootDir}; -> $rootDir: ${JSON.stringify(rootDir)};, by inserting a value you break the sass tokenizer