mizdra / happy-css-modules

Typed, definition jumpable CSS Modules. Moreover, easy!
MIT License
213 stars 5 forks source link

Resolved an error that occurs when using with sass 1.60.x #205

Closed mkusaka closed 1 year ago

mkusaka commented 1 year ago

First of all, thank you for creating this wonderful CLI. I use it all the time and it has been a great help.


Currently, when used with the latest version of sass, which is 1.63.3, an error occurs.

repro: on this branch

❯ git checkout 3d3c8fb8bb2732c8ff293236c31bbe877aa1b14e
...
❯ npm i
...
❯ npm run test

> test
> NODE_OPTIONS="--experimental-vm-modules $NODE_OPTIONS" jest

 FAIL  packages/happy-css-modules/src/transformer/scss-transformer.test.ts
  ● handles sass features

    TypeError: Cannot read properties of undefined (reading 'render')

      12 |   return async (options: LegacyOptions<'async'>) => {
      13 |     return new Promise<LegacyResult>((resolve, reject) => {
    > 14 |       sass.render(options, (exception, result) => {
         |            ^
      15 |         if (exception) reject(exception);
      16 |         else resolve(result!);
      17 |       });

      at render (packages/happy-css-modules/src/transformer/scss-transformer.ts:14:12)
      at packages/happy-css-modules/src/transformer/scss-transformer.ts:13:12
      at Locator.render [as transformer] (packages/happy-css-modules/src/transformer/scss-transformer.ts:27:26)
      at Locator.readCSS (packages/happy-css-modules/src/locator/index.ts:119:20)
      at Locator._load (packages/happy-css-modules/src/locator/index.ts:157:40)
      at Locator.load (packages/happy-css-modules/src/locator/index.ts:143:20)
      at Object.<anonymous> (packages/happy-css-modules/src/transformer/scss-transformer.test.ts:40:18)

....

Test Suites: 5 failed, 14 passed, 19 total
Tests:       9 failed, 1 todo, 100 passed, 110 total
Snapshots:   53 passed, 53 total
Time:        6.714 s, estimated 7 s
Ran all test suites.

This is likely due to breaking changes introduced by sass.

ref. https://github.com/sass/dart-sass/issues/2011

In this PR, we will avoid this by using the default when importing, if it exists, and not using the default if it doesn't.

mizdra commented 1 year ago

@mkusaka This is shipped in 2.1.2. Please could you try it?

mkusaka commented 1 year ago

@mizdra

Thank you for notifying me. :)

I've just updated to version 2.1.2 in my workspace and verified that everything is functioning as it should :tada:.

I appreciate your support. 🙏