sass-loader: includePaths do not work with Webpack 2
Hi everyone, I am using Windows 10 x64 and Webpack 2, with sass-loader version 4.1.1 , but can’t use standard syntax
use: [
{loader: 'style-loader'},
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
includePaths: [
path.resolve(__dirname, 'vendor/zurb/foundation/scss'),
path.resolve(__dirname, 'node_modules/motion-ui/src'),
path.resolve(__dirname, 'resources/assets/sass')
],
sourceMap: true
}
}
]
The only way to get this to work is to use LoaderOptionsPlugin
new webpack.LoaderOptionsPlugin({
options: {
context: '/', // <- putting this line right under "options" did the trick
sassLoader: {
includePaths: [
path.resolve(__dirname, 'vendor/zurb/foundation/scss'),
path.resolve(__dirname, 'node_modules/motion-ui/src'),
path.resolve(__dirname, 'resources/assets/sass')
]
}
}
})
Otherwise it throws an error saying can’t import ‘foundation’ and so on. LoaderOptionsPlugin stops to work as of version 5.0.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 32 (12 by maintainers)
The sass-loader has its own loader pipeline. This configuration fixed the issue:
This is my config and it’s working with your sass-loader-test repository
@jhnns hey just tested
options: { includePaths: [...] }
withsass-loader@6.0.2
and it worked fine. I think this may be ok to close 👍 .No problem. You’re welcome 😃
I’m willing to help if the other side is providing a test repository. This makes spotting bugs/wrong configurations a lot easier.
@asolopovas with sass-loader 4.1.1 and webpack 2.2.1, both config examples work.
With sass-loader 5.0.1,
webpack.config.js
does not work because the sass-loader doesn’t read the config from the webpack options object anymore. You don’t need to use theLoaderOptionsPlugin
with sass-loader 5.0.0 anymore. Just specify the loader options directly. Thus,webpack.config.error.js
does work.@asolopovas Same issue here after upgrading to 5.0.0. Your suggested solution did not fix mine elas… Rolled back to 4.1.1 and issue disappeared.
Oh, I don’t think that this is a hack solution. Since a
vue
file can host a lot of file types, it makes sense to have a dedicated loader pipeline because webpack’s loadertest
algorithm wouldn’t work here.@janusch Could you try the latest sass-loader on master branch? If it’s still not working, you can try to comment out these lines. Does it work then? How do the paths look like when they come from node-sass?
Ok, now I can reproduce this error on Windows (doesn’t happen on macOS):
It seems like node-sass is exporting source maps with forward slashes (which are also valid on Windows). Webpack’s source map module, however, stores backslash paths. That’s why the source maps can not be resolved.
I can fix this in sass-loader by applying
path.normalize
on all source map paths.Next time, please always post the actual error message including the stack trace.
Also check out our tests.
Thank you. I use
LoaderOptionsPlugin
and rollback sass-loader to 4.1.1. It work.@asolopovas includePaths work fine for me in 4.1.1:
new webpack.LoaderOptionsPlugin({ options: { sassLoader: { includePaths: [ path.resolve(__dirname, '../src/app/assets/sass'), path.resolve(__dirname, '../node_modules/bootstrap/scss') ] } } })