stencil-sass icon indicating copy to clipboard operation
stencil-sass copied to clipboard

Build fails with "Can't find stylesheet to import." if injectGlobalPaths is used

Open jase88 opened this issue 4 years ago • 13 comments

Current Behavior

If using injectGlobalPaths parameter

plugins: [
    sass({
      injectGlobalPaths: ['src/globals/variables.scss'],
    }),
  ],

the build fails with

[ ERROR ]  sass error: ...tencil-example/libs/web-components/src/components/my-component/my-component.scss:1:9
           Can't find stylesheet to import.

If I leave out the parameter, the builds succeeds.I suspect the path resolution not working correctly on my nx workspace, because it works on a simple stencil project.

Expected Behavior

using injectGlobalPaths parameter should work without causing issues

Context (Environment)

  • nx 11 workspace
  • @stencil/core 2.3.0
  • @stencil/sass: 1.4.1
  • Windows

Steps to Reproduce

  1. clone https://github.com/kerosin/nx-stencil-example
  2. call nx build web-components

jase88 avatar Jan 26 '21 12:01 jase88

reason is that context.config.rootDir points to nx-stencil-example\dist\libs\web-components instead of nx-stencil-example/libs/web-components/stencil.config.ts

So resolving the paths injectGlobalPaths is errornous and causes an error on the dart sass package.

jase88 avatar Feb 01 '21 13:02 jase88

@jase88 Is there any workaround for this issue? For me this feature is completely broken right now :(

janrembold avatar Apr 23 '21 07:04 janrembold

I'm also having issues with this. nx workspace using stencil, and I'm getting the same error when trying to inject global paths. Anyone come up with a workaround?

corysmc avatar May 15 '21 16:05 corysmc

So what this global path does is just adding your globals to the head of each scss file with @use myGlobal.

So the only workaround I can think of would be a own script that automatically writes your global files at the top :/

jase88 avatar May 15 '21 16:05 jase88

Thanks @jase88 that helps!

corysmc avatar May 16 '21 16:05 corysmc

You could try version 2.0.0-0, which is released 13 days ago but with dist-tag next instead of latest

tfrijsewijk avatar May 22 '21 13:05 tfrijsewijk

I just faced the same issue while trying to move my NPM monorepo to Nx workspaces, what worked for me with @stencil/sass v1.5.2 was concatenating the path with __dirname:

plugins: [
  sass({
    injectGlobalPaths: [`${__dirname}/src/globals/variables.scss`],
  }),
],

Hope it helps 🙂

dgonzalezr avatar Apr 01 '22 06:04 dgonzalezr

@dgonzalezr This works for me! Nice man thanks!

Wvduijn avatar Apr 07 '22 12:04 Wvduijn

Even with the solution proposed by @dgonzalezr , I'm getting the same "Can't find stylesheet to import" error. Is there any updates on this issue?

rallz-dev avatar May 02 '22 14:05 rallz-dev

We are seeing the same issue, but fixed on Mac/Linux when using the fix from @dgonzalezr. It still doesn't work on Windows though.

jaredtbates avatar Sep 30 '22 16:09 jaredtbates

This fixed the issue on Windows:

import path from 'path';

...

  plugins: [
    sass({
      injectGlobalPaths: [
        path
          .resolve(__dirname, `src/styles/variables.scss`)
          .replace(/\\/g, '/'),
      ],
    }),
  ],

jaredtbates avatar Sep 30 '22 19:09 jaredtbates

This fixed the issue on Windows:

import path from 'path';

...

  plugins: [
    sass({
      injectGlobalPaths: [
        path
          .resolve(__dirname, `src/styles/variables.scss`)
          .replace(/\\/g, '/'),
      ],
    }),
  ],

Indeed, my solution only works on Unix, I was struggling with the same issues on Windows, @jaredtbates you've "saved my life" 😆 )))

dgonzalezr avatar Oct 02 '22 17:10 dgonzalezr

Hello, guys, if you have worked before with sass, the imports are usually @import 'my-sass-file', without extension. Also many times we are not used to use './......' in our imports, for which this could be helpful: for example, my file is called colors.scss

plugins: [
   sass({
     injectGlobalPaths: [
       './src/global/colors'
     ],
   }),
 ],

I hope it helps.

damorossi avatar Jan 12 '23 12:01 damorossi