css-loader: Error can't find module when using less-loader and "module" options
Hello,
when i use "background: url(./icon.png)" in my less file i got error Module not found: Error: Cannot resolve module 'icon.png'.
Here part of webpack.config.js file
module: {
loaders: [
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style', 'css?module&localIdentName=[hash:base64:5]!postcss!less')
},
{
test: /\.(jpg|png)$/,
loader: 'url-loader?limit=100000'
},
{
test: /\.svg$/,
loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
}
]
},
If remove module options or less-loader all works well.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 3
- Comments: 50 (6 by maintainers)
This is what worked for me. Add to webpack config the following lines
@zxcabs @markdalgleish lol, you know what worked?
No changes to loader at all.
It’s installed. Still doesn’t work.
background: url("./img/login-background.png") no-repeat 0 0;Module not found: Error: Cannot resolve module 'img/login-background.png' in c:\Users\spybo\Documents\Projects\project\src\frontend\components\login\EntrancePageHad the same with webpack 2 and css-modules on
background: url("\./img/logo.png"); //workhelpedI know one more fix for less:
~"url()".My workaround was that I’ve created additional temporary loader called (just local
.jsfile called_less-loader-fix.js):And using it in
webpack.config.jslike this:Present
RegExmight not cover all use-cases, so you might want to extend it a bit on demand.make sure you install
less:npm install less -Dless-loaderwon’t auto installlessAny update to this? Having near-exactly the same error as @NicoBurno - Using:
@michael-ciniawsky there are two error sections:
Section 1
Section 2
Please try again with
less-loader >= v4.0.0, if there are still regressions I will reopen 😛background: url("\./images/cat.png");does not work for me. As a temporary solution I added ‘image’ folder to webpack resolve fallback path. I still cannot load image or font from the stylus file’s folder.@zxcabs I kind of debugged all the chain and it is quite clear where exactly the issue, but that code was written on purpose…
When I changed:
to
Everything works fine.