css-loader: Import error with modules mode, composes and sass
I have a project in which I have a Card
and CardContainer
component. The idea is that the Card
can be used in isolation if desired, or multiple cards can be used inside a CardContainer
which will arrange its cards in a grid and provide scrolling if necessary. In order to facilitate this, the container’s CSS needs to modify the flex attributes of its children (adding flex 1 1 auto
for example).
I’m using sass (via sass-loader) and each of my component sass files imports a utils.scss
a couple of directories down, which works fine without composes
, but with it I am getting a file not found on the utils.scss
from the file being imported for composition.
This is my directory structure:
src/
components/
Card.jsx
Card.scss
CardContainer.jsx
CardContainer.scss
...
sass/
_utils.scss
...
My (simplified) Card.scss
looks like this:
@import '../sass/utils';
.card {
...
}
My (again simplified) CardContainer.scss
looks like this:
@import '../sass/utils';
.card {
composes: card from './Card.scss';
}
.cardContainer {
& > .card {
...
margin: 0 $gutter $gutter 0;
flex: 1 1 auto;
width: 30%;
}
}
The error I see is:
Module not found: Error: Cannot resolve 'file' or 'directory' ../sass/utils in <path to project>/src/components
I don’t fully understand how this all fits together but It seems to me that this mechanism is trying to resolve a js/jsx file rather than going through the sass pipeline. Does this make sense to you? It’s resolving ./Card.scss
just fine - it’s the secondary import that doesn’t seem to be working.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 12
- Comments: 16 (2 by maintainers)
I just discovered something last night that I’m not sure how I ever missed: https://github.com/webpack/css-loader#importing-and-chained-loaders
In my case, importLoaders was set to “1”, but it needed to be set to “2” so that the sass-loader is picked up by Webpack on @-imports. This fully resolved my issue with using sass and css-modules together.
Have similar issue with stylus. It seems to be that the stylus loader from the configuration file is not getting called. In my case transforming the styl file within the compose helped.
In your case you have to call the sass loader instead of stylus.
michael-ciniawsky Is there any update on this? 💪
@michael-ciniawsky This is still not working.
Please try with the latest
stylus-loader, sass-loader
, if there are still regressions I will reopen 😛