nvh95 / jest-preview

Debug your Jest tests. Effortlessly.🛠🖼
https://www.jest-preview.com
MIT License
2.34k stars 76 forks source link

Error 'Can't find stylesheet to import' with CSS Modules with SCSS #311

Open JusteZil opened 9 months ago

JusteZil commented 9 months ago

Describe the bug

If users use jest-preview with vite, CSS modules with SCSS and import stylesheet with an absolute import like this @import 'src/styles', the following error is thrown:

● Test suite failed to run. 

Can't find stylesheet to import.
  ╷
1 │ @import 'src/styles';
  │         ^^^^^^^^^^^^
  ╵
  src\components\Button\Button.module.scss 1:9  root stylesheet

I attempted to utilize the sassLoadPaths configuration option and set up jest moduleNameMappers such as 'src/(.*)': '<rootDir>/src/$1', but it appears that none of these changes are taking effect. Using a relative import could be a solution to the problem; however, implementing such a change in the existing project is not feasible.

Screenshots

Folder structure:

image

Import example:

image

Error:

image

Reproduce

You can find a minimal reproducible example in this repository, and its code is adapted from the example demonstrated in jest-preview vite-react-example.

Expected behavior

No errors

Environment

Additional context

Seems that the same issue was already reported in https://github.com/nvh95/jest-preview/issues/224 without further resolution.