0

I'm trying to run frontend unit tests in my Angular app using Karma. I can't get the tests to compile though, when running 'ng test' in the console it fails with this error message:

Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
  ╷
1 │ @use 'internal-library' as *;
  │ ^^^^^^^^^^^^^^^^^^^^^^
  ╵
  ../../../src/styles/global.scss 1:1  @import
  ../../../src/styles/styles.scss 8:9  root stylesheet

How can I exclude compiling stylesheets from karma? Or is there another solution I should try?

Re: the first comment, I updated my angular.json as the other answer suggested, with this:

"styles": [
              "src/styles/styles.scss"
            ],
            "stylePreprocessorOptions": {
              "includePaths": [
                "src/styles"
              ]
            },

(Adapted to my file structure)

-src
  -styles
      -global.scss -> here's the import it's struggling with
      -styles.scss -> the global file is then imported here
    -api
      -mixins.scss
      -variables.scss
gizmo
  • 81
  • 8
  • Does this help? https://stackoverflow.com/a/64989212/7365461 – AliF50 May 27 '21 at 13:31
  • Hi, I added the `stylePreprocessorOptions` to my angular.json but it's still failing with the same error.. Should I just add the paths to my stylesheets there or should I add the paths to the lib it's unable to import? – gizmo May 27 '21 at 14:27
  • I think try adding paths to the lib it's unable to import. – AliF50 May 27 '21 at 14:39
  • That also didn't work, when I added it to `stylePreprocessorOptions` nothing changed, and when I added it to `styles` I got an error since it tried to find the lib files in my project (and the lib is in a separate project) – gizmo May 27 '21 at 14:50
  • I don't know how to fix it then, sorry. – AliF50 May 27 '21 at 14:51

0 Answers0