Strangely, the loadPaths attribute doesn't work, what worked for me was using includePaths:

                {
                    loader: 'sass-loader',
                    options: {
                        sassOptions: {
                            includePaths: [path.resolve(__dirname, 'Develop', 'Styles')]
                        }
                    }
                }
Answer from violetflare on Stack Overflow
🌐
GitHub
github.com › webpack-contrib › sass-loader › issues › 593
import with includePaths not work for sass-loader 7.x #593
July 17, 2018 - module.exports = { entry: { index: './src/index.js' }, module: { rules: [{ test: /\.scss$/, use: [ 'style-loader', 'css-loader', { loader:'sass-loader', options: { includePaths: [ './src/scss' ] }} ] }] } }
Author   jackysee
🌐
Stack Overflow
stackoverflow.com › questions › 62702214 › webpack-sass-loader-cant-figure-out-how-includepaths-work
Webpack - sass-loader can't figure out how includePaths work - Stack Overflow
TL/DR: Why is it, that webpack does not find my config.scss file based on the second includePath provided, but can resolve it based on the first? Yet it will resolve the test.scss file in any case? ... //webpack.config.js ... unrelated code ... module.exports = merge(common, { ... unrelated code ... modules: { rules: [ { test: /\.s(a|c)ss$/, exclude: /\.module.(s(a|c)ss)$/, loader: [ { loader: MiniCssExtractPlugin.loader }, { loader: 'css-loader', options: { sourceMap: true } }, { loader: 'sass-loader', options: { sourceMap: true, implementation: require('sass'), sassOptions: { importer: globImporter(), includePaths: [path.resolve(__dirname, './src/main/'), path.resolve(__dirname, './src/main/config/')] } }, } ] } ] }, ...
🌐
GitHub
github.com › Shopify › slate › issues › 785
Adding includePaths to sass-loader · Issue #785 · Shopify/slate
September 27, 2018 - Problem I'm trying to include Material Design in my theme. In order to do this, I need to add the includePaths to to sass loader as follows: { loader: 'sass-loader', options: { includePaths: ['./node_modules'], }, This is outlined in Mat...
Author   adamwooding
🌐
GitHub
github.com › webpack-contrib › sass-loader › issues › 756
options has an unknown property 'includePaths'. if .scss file is empty · Issue #756 · webpack/sass-loader
September 4, 2019 - Module build failed (from ./node_modules/sass-loader/dist/cjs.js): ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema. options has an unknown property 'includePaths'. These properties are valid: object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter?
Author   kambbado
🌐
webpack
webpack.js.org › loaders › sass-loader
sass-loader | webpack - JS.ORG
If it cannot be resolved, then the loader will try to resolve @import inside node_modules. Prepending module paths with a ~ tells webpack to search through node_modules. ... It's important to prepend the path with only ~, because ~/ resolves to the home directory. Webpack needs to distinguish between bootstrap and ~bootstrap because CSS and Sass files have no special syntax for importing relative files.
🌐
Sass
sass-lang.com › documentation › js-api › interfaces › legacyfileoptions
Sass: LegacyFileOptions | JS API
Load paths are also loaded from the SASS_PATH environment variable, if it’s set. This variable should be a list of paths separated by ; (on Windows) or : (on other operating systems). Load paths from the includePaths option take precedence over load paths from SASS_PATH.
🌐
JetBrains
youtrack.jetbrains.com › issue › WEB-28296 › webpack-provide-support-for-sass-loader-includePath-property
webpack: provide support for sass-loader `includePath` property
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
Find elsewhere
🌐
GitHub
github.com › webpack-contrib › sass-loader › issues › 366
includePaths do not work with Webpack 2 · Issue #366 · webpack/sass-loader
February 7, 2017 - 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') ] } } })
Author   asolopovas
🌐
GitHub
github.com › webpack-contrib › sass-loader
GitHub - webpack/sass-loader: Compiles Sass to CSS · GitHub
If it cannot be resolved, then the loader will try to resolve @import inside node_modules. Prepending module paths with a ~ tells webpack to search through node_modules. ... It's important to prepend the path with only ~, because ~/ resolves to the home directory. Webpack needs to distinguish between bootstrap and ~bootstrap because CSS and Sass files have no special syntax for importing relative files.
Starred by 3.9K users
Forked by 428 users
Languages   JavaScript 80.2% | SCSS 8.9% | Sass 8.8% | HTML 1.8% | CSS 0.3%
🌐
GitHub
github.com › webpack-contrib › sass-loader › issues › 400
includePaths not resolving properly? · Issue #400 · webpack/sass-loader
March 7, 2017 - sassLoader: { includePaths:[ path.resolve(__dirname, './node_modules/foundation-sites/scss') ] }, module:{ loaders:{ ...., { test: /\.scss$/, loader: ExtractTextPlugin.extract([ 'css?sourceMap&importLoaders=1&-url', 'resolve-url', 'postcss', 'sass?sourceMap' ]) }, ...., } }
Author   jkinzel-r7
Top answer
1 of 3
7

You can use Webpack aliases. Resolving every import /templates to your project's templates/ folder.

const path = require('path');

module.exports = {
  // ...
  resolve: {
    alias: {
      '/templates': path.resolve(__dirname, './templates')
    }
  }
};

I read @sympony/webpack-encore and found addAliases setting. You can use as the following example.

const path = require('path');
const Encore = require('@symfony/webpack-encore');

Encore
  // ...
  .addAliases({
    '/templates': path.resolve(__dirname, './templates')
  });

In your Scss/SASS on import use ~ ahead file path.

@import '~/templates/common/variables'
  • Webpack alias reference
  • @symfony/webpack-encore addAliases reference
  • sass-loader import reference
2 of 3
1

Probably you already found the answer yourself, but just in case some else gets here the common way of using url() with paths relatives to the file where they are imported is using resolve-url-loader. Also note that you have to set the sourceMap to true in the preceding loaders.

https://www.npmjs.com/package/resolve-url-loader

That's an example on how to use it:

{
    // Note that sourceMap is needed to be true at least in sass-loader so resolve-url-loader works fine
    test: /\.scss$/,
    use: [
        {
            loader: "style-loader",
            options: { sourceMap: true }
        }, // Adds CSS to the DOM by injecting a <style> tag
        {
            loader: "css-loader",
            options: { sourceMap: true }
        }, // The css-loader interprets @import and url() like import/require() and will resolve them.
        {
            loader: "postcss-loader",
            options: {
                sourceMap: true,
                plugins: [
                    require("autoprefixer")({ browsers: ["last 2 versions"] })
                ]
            }
        }, // Adds prefix for cross-browser support
        {
            loader: "resolve-url-loader",
            options: { sourceMap: true }
        }, // Webpack loader that resolves relative paths in url() statements based on the original source file.
        {
            loader: "sass-loader",
            options: { sourceMap: true }
        } // Loads a Sass/SCSS file and compiles it to CSS.
    ]
}
🌐
Roots Discourse
discourse.roots.io › sage
How add paths to sass include path? - sage - Roots Discourse
May 11, 2017 - How can custom/external paths be added to include paths used by sass in latest sage (9.x)? I sifted through the webpack config and scripts but I can’t find the place that is responsible for compiling with sass.
🌐
npm
npmjs.com › package › sass-loader › v › 7.2.0
sass-loader - npm
August 9, 2019 - loader: "sass-loader", options: { includePaths: ["absolute/path/a", "absolute/path/b"] } }] }] } }; See the Node Sass documentation for all available Sass options. By default the loader resolve the implementation based on your dependencies. Just add required implementation to package.json (node-sass or sass package) and install dependencies.
      » npm install sass-loader
    
Published   Feb 05, 2026
Version   7.2.0
Author   J. Tangelder
🌐
Lightrun
lightrun.com › answers › kitze-custom-react-scripts-include-src-path-for-sass-loader
Include `src/` path for sass-loader - Lightrun
In your Scss/SASS on import use ~ ahead file path. ... that resolves relative paths in url() statements based on the original source...Read more > ... The loader will first try to resolve @import as a relative path.
🌐
GitHub
github.com › rails › webpacker › issues › 1245
How to add `includePaths` to Sass loader · Issue #1245 · rails/webpacker
February 3, 2018 - // config/webpack/environment.js const { environment } = require('@rails/webpacker') environment.loaders.prepend('sass', { test: /\.(css|scss|sass)$/, use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'sass-loader', options: { includePaths: ['node_modules'], } }] }) module.exports = environment ·
Author   jonhue
🌐
W3cubDocs
docs.w3cub.com › webpack › loaders › sass-loader
Sass-loader - Webpack - W3cubDocs
Add the missing url rewriting using the resolve-url-loader. Place it before the sass-loader in the loader chain. Library authors usually provide a variable to modify the asset path. bootstrap-sass for example has an $icon-font-path.
🌐
JetBrains
youtrack.jetbrains.com › issue › WEB-28296
Jetbrains
December 27, 2021 - {{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong