You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Generated image urls *must* be absolute for style!css?sourceMap to work? #55
Ah interesting. Thanks for sharing! I'll try that out.
For now, I actually ended up going about it slightly differently. Since my main issue was being able to use url('/images/sample.png') paths in CSS I defined ?root query string parameter for the css-loader and then specified ?name=[path][name].[ext] for the url-loader. This seemed to do the trick without having to specify the full URL in publicPath.
@tizmagik It will be helpful if you can provide a sample webpack.config.js or just loaders. Thanks in advance. @valerymercury set output.publicPath is a workround.
@creeperyangoutput.publicPath isn't working for me. As @tizmagik said root option helped me to fix bug with background images in css. I resolved my problem with the following config:
Has this been tested with relative pathed images (e.g. url(image.png))? It seems the solution provided is for absolute path images (e.g. url(/image.png)). I can't seem to use either solution suggested.
Still not working for me with an absolute public path, e.g. /build/. Even including the full public URL e.g. http://example.com/build/ does not seem to work.
Reacted by G. Sitthi, Vishwanath Arondekar, Charles Prescott Collins IV, Nick Presta, Idan Gozlan, Samuel Jackson, Sam A. Horvath-Hunt, Jeremy Bernier, R.G., Thomas Boland and 5 more
just stumbled over this. if setting publicPath is not working for you, you probably are making the same mistake as I was by setting publicPath in the devServerconfig. it should be set in the webpack root config object in output. have a look:
doesn't work:
// your webpack config{devServer: {publicPath: 'http://127.0.0.1:8888/'// ... more devServer config}// ... more webpack config}
works for me:
// your webpack config{
output: {publicPath: 'http://127.0.0.1:8888/'// ... more webpack output config}
devServer: {// ... your devServer config}// ... more webpack config}
be sure to only set it in dev, who knows what this would do to your production build. good luck!
Hi! I've tried every combination I could possibly think of and I can't understand why my images aren't found...
Here is my configuration:
output: {
path: distPath,
// Set proper base URL for serving resources
publicPath: '/',
// The output filename of the entry chunk, relative to `path`
// [name] - Will be set per each key name in `entry`
filename: 'bundle.[hash].js'
},
.....
// SCSS
{
test: /\.(css|scss)$/,
loaders: [
'style-loader',
'css-loader?root=' + encodeURIComponent(appPath),
'postcss-loader',
'sass-loader?includePaths[]=' + encodeURIComponent(appPath)
]
},
{
test: /\.(jpe?g|png|gif|svg)(\?.*)?$/i,
loader: 'file-loader',
options: {
name: '[path][name].[hash].[ext]',
publicPath: 'http://localhost:8080/', --> Added this because suggested here (in webpack 1 it worked without this
},
}
And i'm requiring the images via scss: background-image: url('/assets/images/login/background_4.jpg');
Webpack output is:
Which is strange, because it used to be: '/assets/images/.....' without the '/Users/uriklar/' part
Ok, so my issue wasn't related (I'll delete my comment if maintainers prefer), but in case someone does get here with the same problem as me, what fixes it for me was adding the: context option to file-loader (i'm actually using url-loader) with the base url that assets need to be loaded from.
It seems with css sourceMaps enabled, even with publicPath set, styles (including bg images) are not applied. But what is odd is that I can see them in the inspector. If I turn the style off and on again then the style is applied.
The below shows the page on initial load, showing a body background of paleturquoise in the dev console but the displayed background is white.
Unchecking and checking a style will then show the correct styles. If the dev console is not open you still have the issue.
Activity
sokra commentedon Apr 20, 2015
yep. Do you want to add one in a PR?
clessg commentedon May 11, 2015
Same problem here. Bit of a confusing bug to run into.
Update README: set publicPath for ?sourceMap to load assets
Darkside73 commentedon Jan 6, 2016
How to deal with HTTPS? Schema-less protocol does not work
tizmagik commentedon Jan 14, 2016
Same question for https
Darkside73 commentedon Jan 14, 2016
I've figured out how to solve HTTPS issue. You can use your own dev server (take a look for
https: trueoption) to serve assets. Here is the example https://gist.github.com/Darkside73/e3b70d72443e0f72b27btizmagik commentedon Jan 14, 2016
Ah interesting. Thanks for sharing! I'll try that out.
For now, I actually ended up going about it slightly differently. Since my main issue was being able to use
url('/images/sample.png')paths in CSS I defined?rootquery string parameter for the css-loader and then specified?name=[path][name].[ext]for the url-loader. This seemed to do the trick without having to specify the full URL inpublicPath.pixelcure commentedon Jan 16, 2016
@tizmagik is this how you resolved the disappearing images? was this in webpack.config.js?
tizmagik commentedon Jan 16, 2016
Yes, it seems to work fine even though using
rootis not recommended according to the docs for whatever reason.valerymercury commentedon Jan 25, 2016
@tizmagik can you provide an example of working config, please?
creeperyang commentedon Jan 31, 2016
@tizmagik It will be helpful if you can provide a sample
webpack.config.jsor just loaders. Thanks in advance. @valerymercury setoutput.publicPathis a workround.valerymercury commentedon Jan 31, 2016
@creeperyang
output.publicPathisn't working for me. As @tizmagik saidrootoption helped me to fix bug with background images in css. I resolved my problem with the following config:tizmagik commentedon Feb 1, 2016
@creeperyang sorry for the late reply, just saw this.
@valerymercury yeap, that's basically what I have as well. Here's mine if it's any more helpful:
davidhouweling commentedon Feb 10, 2016
Has this been tested with relative pathed images (e.g.
url(image.png))? It seems the solution provided is for absolute path images (e.g.url(/image.png)). I can't seem to use either solution suggested.3 remaining items
Strate commentedon Mar 30, 2016
#96
mbritton commentedon Aug 15, 2016
+1
simshanith commentedon Oct 14, 2016
Still not working for me with an absolute public path, e.g.
/build/. Even including the full public URL e.g.http://example.com/build/does not seem to work.Fix up Public Path
Pines-Cheng commentedon Jan 14, 2017
meet the same question, just working for me with an absolute public path.
muralim4242 commentedon Jan 27, 2017
url(${require('app/images/Rectangle-9.jpg')})chore(webpack): use URL loader for png, jpg, gif, woff, woff2, ttf an…
olieidel commentedon Apr 1, 2017
just stumbled over this. if setting
publicPathis not working for you, you probably are making the same mistake as I was by settingpublicPathin thedevServerconfig. it should be set in the webpack root config object inoutput. have a look:doesn't work:
works for me:
be sure to only set it in dev, who knows what this would do to your production build. good luck!
bohdanly commentedon Apr 6, 2017
@simshanith to make it work specify absolute
publicPathforfile-loaderto your local serverit will change URL in your CSS from relative to absolute
urikphytech commentedon Jun 3, 2017
Hi! I've tried every combination I could possibly think of and I can't understand why my images aren't found...
Here is my configuration:
And i'm requiring the images via scss:

background-image: url('/assets/images/login/background_4.jpg');Webpack output is:
Which is strange, because it used to be: '/assets/images/.....' without the '/Users/uriklar/' part
Any idea what i'm missing here??
Thanks!
Uri
uriklar commentedon Jun 4, 2017
Ok, so my issue wasn't related (I'll delete my comment if maintainers prefer), but in case someone does get here with the same problem as me, what fixes it for me was adding the: context option to file-loader (i'm actually using url-loader) with the base url that assets need to be loaded from.
bugfix(css-loader): svg and images not loading when css source maps a…
bugfix(css-loader): svg and images not loading when css source maps a…
xyzdata commentedon Jan 3, 2018
output.publicPath&output.pathhttps://github.com/gildata/RAIO/issues/276#issuecomment-354964693
robbie-hinman commentedon Jan 16, 2018
It seems with css sourceMaps enabled, even with publicPath set, styles (including bg images) are not applied. But what is odd is that I can see them in the inspector. If I turn the style off and on again then the style is applied.
The below shows the page on initial load, showing a body background of paleturquoise in the dev console but the displayed background is white.

Unchecking and checking a style will then show the correct styles. If the dev console is not open you still have the issue.
repo here