sass-loader: [bug?] Webpack aliases being ignored.
I have an alias like this in webpack.config.js:
'common': path.resolve(__dirname, '..', '..', 'common'),
and I have import statements like these in my .scss
files:
@import "common/scss/colors";
but it doesn’t work.
If I change it to
@import "../../common/scss/colors";
just like what the Webpack alias defines, then it works!
I can work around the problem by making my own loader, and modifying the @imports
to have the unaliased strings, but that’s obviously not desirable.
Possibly related: https://github.com/webpack-contrib/sass-loader/issues/173
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 18
- Comments: 24 (3 by maintainers)
+1 same issue, webpack 2
Guys, have you seen this link? 😃 https://getbootstrap.com/docs/4.0/getting-started/webpack/#importing-javascript
I think I’ve resolved this for anyone who is still having this issue. I’ll start with my directory/file layout:
This is the relevant section of my webpack.config.js:
The key with the alias path above is that it must be relative to the location of my webpack.config.js file.
In my entry.js, the modules paths “node_modules” will be used to resolve paths to the .js files that live in NPM directory and the “BootstrapJS” alias will resolve to the Bootstrap JS directory:
When compiled, you should see this message in console:
In my app.scss file, I can import like this:
The “~” is required here because it indicates to Webpacks that this is not a relative import. You can find more information here: https://github.com/webpack-contrib/sass-loader#imports
I’m having this issue and it’s January 2018. What a frustrating bug. I’ve tried every single option here and on the web but webpack just keeps complaining about file not found. Added tilde, removed tilde, modified the resolve settings any way possible, used path.resolve, path.join… and nothing worked. Even the error did not change. Any hints?
Any updates on this issue ?
I have the same issue in webpack 2.
PR welcome 👍
I just did something out of fraustration so check this out. So these do not work:
This one works:
Unfortunately the
.scss
package is referencing@material
packages, which internally do NOT use tilde and so even directly referencing the.scss
file does not work. Here’s my webpack resolve:Still interested in using the
.scss
so I can build themes, so any help is appreciated.@williamboman
So even if I use
@import
inline like this:Or
I get
File to import not found or unreadable
. If instead of using inline loaders you specify it in the Webpack config then just import the file, I can see from the resulting error that it attempted to load the file directly instead of the result of passing the file through the loader I specified.I feel this could be related to this issue as it seems somewhere along the line the
@imported
file skips part of the webpack algorithm.To be honest, I’m not sure if aliases are supported. It should be supported afaik, but we have no test case for that.
Thx for reporting this. I will take a look.
Suppose your alias is ‘$scss’, then you have to use @import ‘~$scss/app.scss’
@SteveOps Intellij does not recognize the imports, but it works with webpack. It’s a bug in IntelliJ already fixed into phpStorm.
Cordialement, Nicolas Trichet
2017-11-11 23:51 GMT+01:00 Steve Ops notifications@github.com: