Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SassError: Can't find stylesheet to import when it contains @forward with _index file #804

Closed
abhiomkar opened this issue Feb 4, 2020 · 63 comments

Comments

@abhiomkar
Copy link

abhiomkar commented Feb 4, 2020

  • Operating System: Mac OS
  • Node Version: v10.16.3
  • NPM Version: v6.13.4
  • webpack Version: v4.41.5
  • sass-loader Version: v8.0.2
  • dart-sass version: v1.25.0

Expected Behavior

Expected sass-loader to resolve the module when _index.scss files are used.

Actual Behavior

sass-loader throws following error when @import'ed Sass file contain @forward statement with _index file. (See reproducible steps below).

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.

Code

See complete example here:
https://github.com/abhiomkar/sass-module-bug

How Do We Reproduce?

git clone [email protected]:abhiomkar/sass-module-bug.git
cd sass-module-bug
npm i
npx webpack

Notice the error:

[./fixture-import.scss] 434 bytes {main} [built] [failed] [1 error]

ERROR in ./fixture-import.scss
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
  ╷
1 │ @forward "@material/base" as mdc-base-*;
  │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  node_modules/@material/button/_mixins.import.scss 1:1  @import
  /Users/abhiomkar/code/sass-bug-module/fixture-import.scss 1:9 

Changing webpack entry file fixture-import.scss => fixture-use.scss would fix the error.

UPDATE: See this comment for temporary workaround.

@alexander-akait
Copy link
Member

alexander-akait commented Feb 5, 2020

@import should support _file.import.extand file.import.ext and prefer using .import files
@use should not

Very strange, when we use @use our importer get those urls:

@material/button/mixins
@material/elevation/mixins
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/variables
@material/animation/variables
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/ripple/mixins
@material/animation/functions
@material/animation/variables
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/mixins
@material/theme/functions
@material/theme/variables
@material/animation/variables
@material/theme/variables
@material/rtl/mixins
@material/theme/functions
@material/theme/mixins
@material/touch-target/mixins
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/typography/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/shape/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/rtl/mixins
@material/shape/functions
@material/density/functions
@material/density/variables
@material/theme/variables
@material/elevation/functions

But when we use @import we have:

@material/button/mixins
@material/base <- invalid import

Investigate deeply.

@alexander-akait
Copy link
Member

alexander-akait commented Feb 5, 2020

Looks like something broken on dart-sass side when you mixed @import and @use, our importer gets invalid URLs for resolve

@alexander-akait
Copy link
Member

alexander-akait commented Feb 5, 2020

Also let's run:

node_modules/.bin/dart-sass --load-path=node_modules fixture-use.scss

All work and fine.

But:

node_modules/.bin/dart-sass --load-path=node_modules fixture-import.scss

No output and no errors

@alexander-akait
Copy link
Member

/cc @nex3 Looks something broken on dart-sass side

@alexander-akait
Copy link
Member

Example without sass-loader:

const sass = require('sass');

const result = sass.renderSync({
    file: './fixture-use.scss',
    // file: './fixture-import.scss',
    includePaths: ['node_modules'],
    importer: function(url, prev, done) {
        console.log(url);
    }
});

console.log(result.css.toString());

For fixture-use.scss:

@material/button/mixins
@material/elevation/mixins
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/variables
@material/animation/variables
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/ripple/mixins
@material/animation/functions
@material/animation/variables
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/mixins
@material/theme/functions
@material/theme/variables
@material/animation/variables
@material/theme/variables
@material/rtl/mixins
@material/theme/functions
@material/theme/mixins
@material/touch-target/mixins
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/typography/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/shape/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/rtl/mixins
@material/shape/functions
@material/density/functions
@material/density/variables
@material/theme/variables
@material/elevation/functions

For fixture-import.scss:

@material/button/mixins
@material/base
@material/feature-targeting
@material/theme
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/animation
@material/elevation
@material/animation/variables
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/mixins
@material/theme/variables
@material/elevation
@material/ripple
@material/animation/functions
@material/animation/variables
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/theme/mixins
@material/theme/functions
@material/theme/variables
@material/animation/variables
@material/theme/variables
@material/ripple
@material/rtl
@material/rtl
@material/touch-target
@material/base/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/touch-target
@material/typography
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/typography
@material/shape
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/rtl/mixins
@material/density
@material/density/variables
@material/theme/variables
@material/elevation/mixins
@material/feature-targeting/functions
@material/feature-targeting/mixins
@material/ripple/mixins
@material/rtl/mixins
@material/theme/functions
@material/theme/mixins
@material/touch-target/mixins
@material/typography/mixins
@material/shape/mixins
@material/shape/functions
@material/density/functions
@material/elevation/functions

@abhiomkar
Copy link
Author

Thanks for looking into this @evilebottnawi

Though the resolved url points to the base url for some stylesheets, for example @material/base, @material/feature-targeting, etc. The final CSS output generated by renderSync() looks correct.

I've updated my code example.

@nex3
Copy link
Contributor

nex3 commented Feb 5, 2020

Also let's run:

node_modules/.bin/dart-sass --load-path=node_modules fixture-use.scss

All work and fine.

But:

node_modules/.bin/dart-sass --load-path=node_modules fixture-import.scss

No output and no errors

Both of these invocations print the same output for me with the latest version of @abhiomkar's repo. I think this is a legit sass-loader bug.

@alexander-akait
Copy link
Member

alexander-akait commented Feb 6, 2020

@nex3 No, please run again and look at result, latest dart-sass, please look on my investigation #804 (comment), why URLs is difference for importer? What is wrong?

I wouldn’t like to spend time studying dart and looking for issues, so I ask you to take a little more responsibility, thanks

@nex3
Copy link
Contributor

nex3 commented Feb 6, 2020

The URLs are expected to be different between @use and @import, because @import is hitting import-only stylesheets.

@alexander-akait
Copy link
Member

alexander-akait commented Feb 7, 2020

@nex3 Where I can found documentation about that? I can't found @material/base in code and where it comes from, providing invalid urls to importer break logic. sass-loader one of their most popular tools to use sass/scss so if we want good support I need information on why this works differently.

@alexander-akait
Copy link
Member

And please stop saying that there are bugs everywhere except your code, we are both developers and may make a mistake in our code, so I prefer to investigate firstly and then say where the problem is. Thanks

@nex3
Copy link
Contributor

nex3 commented Feb 7, 2020

I'm sorry, I didn't mean to cast blame—I only meant to explain why you were seeing that output. @abhiomkar and I were actually initially investigating Dart Sass for a bug here before we ended up determining it was more likely a sass-loader issue and filing this.

The module system is informally documented on the Sass website. The section on imports and modules is particularly relevant here, since it describes how import-only files work.

For more detailed information, you can check out the Sass specification, particularly the sections on modules and @import.

trimox added a commit to trimox/angular-mdc-web that referenced this issue Feb 8, 2020
- Add usage for MDC Sass modules to getting started guide
- Add density mixin examples
- Switch `highlight.js` theme to `scss/github`
- Temporary workaround for webpack-contrib/sass-loader#804
- Load code samples from url
- Refactor and improve performance of template page component
- Update component documentation

closes #2038
@abhiomkar
Copy link
Author

I did some investigation to see how the URLs are resolved. I'm not very familiar with how webpack importer works but seems like resolve() function in webpackImporter is resolving the url to index.js instead of index.scss or _index.scss file. (@trimox spotted this in his comment earlier about presence of index.js causing import failures).

Workaround for now is to disable webpackImporter option in sass-loader:

module.exports = {
  mode: 'development',
  entry: './fixture-import.scss',
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          'css-loader',
          {
            loader: 'sass-loader',
              options: {
+               webpackImporter: false,
                sassOptions: {
                  includePaths: ['node_modules'],
                },
                implementation: require('dart-sass'),
            },
          },
        ],
      },
    ],
  },
};

@evilebottnawi Hope this helps debug the issue :)

@itsUndefined
Copy link

itsUndefined commented Mar 2, 2020

Based upon @abhiomkar investigation I checked how webpack resolves files and came to this conclusion. Webpack only tries to check for the specified extensions only if it doesn't find any valid package.json field based on the mainField option. What we need to fix this issue is one simple line to enforce the required extensions. Google material has javascript files as as the main entrypoint in their package.json. The option is probably https://webpack.js.org/configuration/resolve/#resolveenforceextension . The thing is the documentation that webpack provides is wrong? This option does not enforce requires to have an extension (or does it?) but enforces the resolution to use the extensions options. I confirmed this fact right here: https://github.com/webpack/enhanced-resolve#resolver-options . It clearly states that it is doing exactly what we want "Enforce that a extension from extensions must be used".

@ArthurGerbelot
Copy link

ArthurGerbelot commented Mar 17, 2020

@abhiomkar Do we have a known solution for app using Create React App (without ejecting) ?

@alexander-akait
Copy link
Member

I will work on that fix tomorrow

@alexander-akait
Copy link
Member

@nex3

You aren't actually passing {file: 'directory/index.js'} back to Sass, though, right? If you're somehow converting a JavaScript file into Sass, why does it matter whether the initial import is coming from a @use or an @import? That should only matter if you're loading a Sass file that actually exists on disk, in which case the Sass implementation will handle it foryou.

We can't support this case, because sass fails with a resolved error, because sass doesn't support it, so as I written above, we need to run sass.resolve before run webpack.resolve. webpack have a lot of abilities which sass does not support, but we cannot implement them because sass throw an error when it can be resolved.

I'll try to repeat it again 😞 :

We have node_modules/package:

package.json

{
  "scss": "other.scss"
}

index.scss

$color: red;

a {
  color: $color;
}

other.scss

$color: blue;

a {
  color: $color;
}

And we have this in our file:

*style.scss

@import 'package'; 

If you run pure sass with includePaths: ['node_modules'] you will get:

$color: red;

a {
  color: $color;
}

But if you run sass-loader with includePaths: ['node_modules'] you will get:

$color: blue;

a {
  color: $color;
}

Why? Because sass-loader uses webpack.resolve and webpack.resolve supports more abilities (I can demonstrate many more examples with problems). Here is our main problem. We cannot ask sass - "Can you resolve it or not?". To achieve this we emulate sass resolving algorithm. And when something added or changes in sass algorithm, we need fix it too. All issues with wrong resolutions in sass-loader repo because of this. And this problem too. Now we can not fully emulate sass resolution system because we don't know is it @import or @use because sass uses difference logic.

I know you ask again why not just pass { file: 'package/index.scss'} and sass do this job. Because we can't do it because:

  • @import 'package'/@use 'package', can be taken from the style field (it can be any fields - css, sass, sass, style, my-custom-crazy-field).
  • It can be alias, so we run webpack.resolve.
  • It can my-alternative-index.scss (can be any too).

We should give preference to sass resolving. But this is not the right decision at all, I can’t find the last discussion (we already do request for implementation this to sass team), but no solution(s), it was closed, now everything is going back in the same circle, and I can’t understand why.

Another example:

Then we do (with includePaths: ['node_modules/packages'], where color-utils directory stored):

@import 'color-utils'; 

If you run pure sass it try to resolve node_modules/packages/color-utils/index.scss.
If you run sass-loader it try to resolve color-utils module and in theory color-utils can be exists at node_mdoules/color-utils (it is just a package with JS files). So we do invalid resolving. This example again shows why we should first ask sass.resolve and then webpack.resolve.

In your example code here, you try to resolve a URL using sass.resolve() and then, if that fails, try resolving it using webpack.resolve(). By the time you get to the webpack.resolve() call, the code isn't doing anything Sass-specific. My question is, how do you make sure a Webpack-specific string like ~name checks for Sass-specific names like _name.scss and name/_index.scss?

@nex3 webpack.resolve known how to do it. You don’t have to think about webpack.resolve, it can changed and improved anytime, for example we want to implement remote resolving.

I didn't realize you thought of this as a last resort. Can you point me to the place where it's a major slowdown? Maybe we can communicate better in code than we have been in prose.

I can explain it easily - most sass files in most projects are written with sass compatibility (you can run sass index.scss CLI and all compiled fine), no webpack specific abilities - alias(es), multiple mainFields, custom mainFiles, without other abilities. As you understand every feature require time. For example, checking on aliases may take a long time, but why should we do this, if most of files compatibility with sass. And the ability to check can sass resolve @import/@use solve this problem. We just do not start webpack.resolve - less memory/decrease build time.

@nex3
Copy link
Contributor

nex3 commented Jun 2, 2020

Why? Because sass-loader uses webpack.resolve and webpack.resolve supports more abilities (I can demonstrate many more examples with problems). Here is our main problem. We cannot ask sass - "Can you resolve it or not?". To achieve this we emulate sass resolving algorithm. And when something added or changes in sass algorithm, we need fix it too. All issues with wrong resolutions in sass-loader repo because of this. And this problem too. Now we can not fully emulate sass resolution system because we don't know is it @import or @use because sass uses difference logic.

I totally understand that Webpack supports more resolution capabilities than Sass on its own. That's natural and expected. The point I'm making is that the question you want to ask, "Can you resolve it or not?", is not affected by import-only files.

I know you ask again why not just pass { file: 'package/index.scss'} and sass do this job.

I understand why you can't return {file: 'package/index.scss'}—the package says that other.scss is its entrypoint, so you should return {file: 'package/other.scss'}.

But if you do return the latter result, import-only files will automatically work without any need for extra logic in sass-loader. After your importer returns package/other.import.scss, if package/other.import.scss exists and an @import is being resolved, Sass will convert the response to package/other.import.scss.

In other words, the importer still gets to do all its Webpack-specific logic and pop out whichever result would be correct for @use, and Sass will handle adjusting that result for @import. This is why sass-loader does not have to emulate different logic for @use and @import.

If you run sass-loader it try to resolve color-utils module and in theory color-utils can be exists at node_mdoules/color-utils (it is just a package with JS files). So we do invalid resolving.

I'm having trouble understanding this. What's the problem if color-utils exists at node_modules/color-utils? If it's just a package with JS files, doesn't that mean that the plain Sass importer won't work either?

In your example code here, you try to resolve a URL using sass.resolve() and then, if that fails, try resolving it using webpack.resolve(). By the time you get to the webpack.resolve() call, the code isn't doing anything Sass-specific. My question is, how do you make sure a Webpack-specific string like ~name checks for Sass-specific names like _name.scss and name/_index.scss?

@nex3 webpack.resolve known how to do it. You don’t have to think about webpack.resolve, it can changed and improved anytime, for example we want to implement remote resolving.

You say that webpack.resolve knows how to do it, but I can't imagine that it knows all the Sass-specific rules for when to add underscores for partials or the relative precedence of .scss versus .css files. How would you handle those in your example code in this comment?

I can explain it easily - most sass files in most projects are written with sass compatibility (you can run sass index.scss CLI and all compiled fine), no webpack specific abilities - alias(es), multiple mainFields, custom mainFiles, without other abilities. As you understand every feature require time. For example, checking on aliases may take a long time, but why should we do this, if most of files compatibility with sass. And the ability to check can sass resolve @import/@use solve this problem. We just do not start webpack.resolve - less memory/decrease build time.

If all you're looking for is prioritizing plain-Sass import path resolution above custom importers, that's something that will almost certainly be possible as part of sass/sass#2509.

@alexander-akait
Copy link
Member

alexander-akait commented Jun 4, 2020

@nex3 Tired 😞 , I’ve been trying to show you a design error for several months now and you’re not doing anything, I support many webpack packages integrated with many different tools, I do not want to show myself smarter than someone else, but I have enough knowledge to show all integrations problems. And you repeat the same thing several times, completely refusing to understand me. I think you need help from another sass core developer(s) here to understand the problems, can you tell who could help with this?

I deeply cannot understand why less team pretty quickly understood us and made improvements.

What is the problem to implement sass.resolve/sass.resolver/visitor api?

THE PROBLEMS

Number 1

  • Developer uses sass-loader
  • Developer setup includePaths: ['./node_modules/framework/']
  • Developer has node_modules/framework/color-utils/index.scss file
  • Developer has color-utils package with index.scss - ./node_modules/color-utils/index.scss
  • Developer write @import 'color-utils';
  • Developer run webpack

We run webpack.resolve and return ./node_modules/color-utils/index.scss to sass, but it is wrong. Because we did not take into account includePaths. Why didn’t we do it? Because webpack.resolve do not use includePaths from sass option. Why are we not doing this? Because it's sass care. What if we take care of this? Because we have to duplicate the sass logic. Could duplication of logic be a bad idea?

Lastly you even have forImport argument here https://github.com/sass/dart-sass/blob/master/lib/src/importer/node/implementation.dart#L95.

Number 2

  • Developer uses sass-loader
  • Developer setup includePaths: ['./node_modules/framework/']
  • Developer has ./node_modules/framework/color-utils.scss file
  • Developer has alias with color-utils to ./src/utils/my-file-with-utils.scss
  • Developer write @import 'color-utils';
  • Developer run webpack

We run webpack.resolve and return ./src/utils/my-file-with-utils.scss to sass, but it is wrong. If you try to compile sass without webpack sass resolve @import ./node_modules/framework/color-utils.scss. We again have a problem with what we need to emulate sass resolution algorithm. And new improvements in sass resolutions algorithm will make us fix it again. It's never ending.

Number 3

  • Developer uses sass-loader
  • Developer has ./custom-directory/unknown/index.scss
  • Developer write @import 'unknown';
  • Developer setup SASS_PATH equals custom-directory
  • Developer run webpack

We run webpack.resolve and spend time on looking alias/node_modules/relative paths/various extensions/other custom configured abilities (many memory and CPU) and no luck. Why did we spend this time/memory/cpu, I don't know? By running sass.resolve we would not have to spend resources.

Why do these problems exist?

From source:

/// * The order of import precedence is as follows:
///
/// 1. Filesystem imports relative to the base file.
/// 2. Custom importer imports.
/// 3. Filesystem imports relative to the working directory.
/// 4. Filesystem imports relative to an includePaths path.
/// 5. Filesystem imports relative to a SASS_PATH path.

We need to emulate logic for everything below /// 2. Custom importer imports.. If we were the last (i.e. 5) it would not be a problem. Above, I have already shown why we do it. Yes we implemented this hack/very terrible solutions https://github.com/webpack-contrib/sass-loader/blob/master/src/webpackImporter.js#L87 (we put working directory, includePaths and SASS_PATH in includePaths variable), but this is not entirely true. For example - we don't throw an error on file.ext and _file.ext. Yes, we can improve it. But keep track of sass algorithm changes is too redundant for us.

If all you're looking for is prioritizing plain-Sass import path resolution above custom importers, that's something that will almost certainly be possible as part of sass/sass#2509.

What am I supposed to do here? Do you suggest me to start implementation and design?


Just say that you don’t want to fix it and save my and your time, it’s not so difficult. I'll just embed the modified sass with fixed algorithm in sass-loader and setup automatic patching and releases. Honestly, I would have done it and no one would have had any problems.

@nex3
Copy link
Contributor

nex3 commented Jun 4, 2020

I think I do understand you. In all of your examples, it seems like you're saying that you want Sass's includePaths resolution to run before sass-loader resolution. That's a reasonable request that we do intend to make possible (although I think it's getting pretty far afield from the initial issue report, which had to do with .import.scss files).

I also think that this isn't that big of a problem in the short-term. The issues you point out are all pretty narrow situations with ambiguous @import rules, where they could reasonably be resolved either according to includePaths/SASS_PATH or according to sass-loader. I don't think it's that surprising that sass-loader takes precedence.

Across all Sass implementations since custom importers were first introduced, they've always taken precedence over the user's load paths. I understand this isn't what users want 100% of the time, but it is frequently what they want and I don't think it's particularly surprising behavior.

What is the problem to implement sass.resolve/sass.resolver/visitor api?

Sass has a strong design process which precludes adding new APIs just because they're useful in the short term. Just tossing together whatever APIs more or less work is why the current importer API is such a mess in the first place. If and when we add new features, we need them to be well-thought-out and thoroughly integrated into the way Sass thinks about things.

The reason sass.resolve() in particular doesn't work well is because Sass doesn't think about includePaths-based import resolution as one monolithic entity. Sass considers each include path to be an importer just like sass-loader is an importer, so it doesn't make sense to say "resolve this URL using includePaths but not any other importers".

On the other hand, it does make sense to say "put sass-loader after any other importers". That's what we're working on designing as part of sass/sass#2509.

If all you're looking for is prioritizing plain-Sass import path resolution above custom importers, that's something that will almost certainly be possible as part of sass/sass#2509.

What am I supposed to do here? Do you suggest me to start implementation and design?

You're a major stakeholder in the importer API and you have strong opinions about how it should look, so certainly it's reasonable for you to contribute to the design. I believe @Awjin is also working on some design work here, so perhaps you and he can collaborate.

@Awjin
Copy link

Awjin commented Jun 4, 2020

@evilebottnawi it looks like you and @nex3 were able to land on the root of your problem. I agree that the following behavior will be useful to have in the new API:

On the other hand, it does make sense to say "put sass-loader after any other importers". That's what we're working on designing as part of sass/sass#2509.

Would this be an acceptable/useful solution for sass-loader?

@alexander-akait
Copy link
Member

@nex3 Good, then what are our actions in the short term? I do not want to leave it in current state. Developers have a problems and these problems annoy them, no matter how good sass has design process. It is real problem and we need to solve it for our developers.

What are your suggestions?

And unfortunately, we most likely cannot solve it without new API or new options. Another idea importer: { order: 'last', load: function(url, prev, done) { } }. I spent a lot of time to show a problem in design, and as a developer, I am responsible to my users (developers), I can’t answer them - Sorry, we have a problem and we don't want to solve them.

You're a major stakeholder in the importer API and you have strong opinions about how it should look, so certainly it's reasonable for you to contribute to the design. I believe @Awjin is also working on some design work here, so perhaps you and he can collaborate.

I don't think I have enough time on this, My task is very simple, as you understand it - ability to run importer after sass resolving.

@alexander-akait
Copy link
Member

Fixed in v9 https://github.com/webpack-contrib/sass-loader/releases/tag/v9.0.0 with some hacks, unfortunately, this can lead to loss of performance in some rare cases, we can do nothing here, hope sass (dart-sass) team improve custom resolving mechanism in future and we can avoid these problems.

The algorithm was improved and tested very well, but I'm still worried about some rare cases when we can do something wrong. So feel free to open a new issue with minimum reproducible test repo if you faced with problems, we will fix it.

@rutwick-alic
Copy link

I did some investigation to see how the URLs are resolved. I'm not very familiar with how webpack importer works but seems like resolve() function in webpackImporter is resolving the url to index.js instead of index.scss or _index.scss file. (@trimox spotted this in his comment earlier about presence of index.js causing import failures).

Workaround for now is to disable webpackImporter option in sass-loader:

module.exports = {
  mode: 'development',
  entry: './fixture-import.scss',
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          'css-loader',
          {
            loader: 'sass-loader',
              options: {
+               webpackImporter: false,
                sassOptions: {
                  includePaths: ['node_modules'],
                },
                implementation: require('dart-sass'),
            },
          },
        ],
      },
    ],
  },
};

@evilebottnawi Hope this helps debug the issue :)

But what about people who don't use Webpack? For my project I use Stencil builder!

@alexander-akait
Copy link
Member

@rutwick-alic Seriously?

@rutwick-alic
Copy link

@rutwick-alic Seriously?

I fail to understand if you're being sarcastic or asking me genuinely. But yeah, Stencil doesn't necessarily require Webpack.

@dessant
Copy link

dessant commented Oct 16, 2020

@rutwick-alic, this issue and repository has nothing to do with your support request, try asking your question on the Slack channel of Stencil: https://stencil-worldwide.herokuapp.com

@whizyrel
Copy link

whizyrel commented Feb 9, 2021

I had the same issue on using both mdc snackbar and banner
SassError: Can't find stylesheet to import.

25 │ @use '@material/button/button-theme';
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

node_modules/@material/banner/_banner.scss 25:1 @use
node_modules/@material/banner/styles.scss 23:1 @use
src/style.scss 15:1 root stylesheet

So I thought if it is an error with webpack blah de blah and
{ ... webpackImporter: false }
solved it at the time, setting webpackImporter: true should fix it and yay it did!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.