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 }}
Repository navigation
chore(webpack/styles): BUG - Backgrounds Urls not working when loaded by styles or styleUrl #759
.showcase-img{
background: url(../../assets/img/light-blue-background.jpg) no-repeat 50% 50%; #doesn't works with and without quotes doubles quotes etc....
background-size: cover;
width: 100%;
height: 500px;
text-shadow: 2px 2px 2px black;
}
Tested on Linux & Windows
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).
No need to push a plunker => Just get the last angular webpack starter (with the material branch or not) and try to use one background url on any css files that are loaded by styles or styleUrl
What is the expected behavior?
No error and the background image displayed on and bacground url working
What is the motivation / use case for changing the behavior?
This break the common use of angular
Please tell us about your environment:
Angular version: 2.0.0-rc.3
Browser: all
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
I think in webpack.comon.js
in css, it misss resolve-url-loader
changed the title [-]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl - Should be P1[/-][+]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl - Should be [/+]on Jul 6, 2016
changed the title [-]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl - Should be [/-][+]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl[/+]on Jul 6, 2016
changed the title [-]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl[/-][+]chore(webpack/styles): BUG - Backgrounds Urls not working when loaded by styles or styleUrl[/+]on Jul 6, 2016
I have almost the exact problem when using 'to-string-loader', 'css-loader' in webpack.
Looks like this is a problem with all (most) files css loads using url..
I am using rc.4.
Not sure if this is relevant, but I've seen variations of the error line based on different images.
JPG encoded on Photoshop 3.0 (I guess?): (function (exports, require, module, __filename, __dirname) { ����2�Photoshop 3.0
JPG encoded on my Windows box: (function (exports, require, module, __filename, __dirname) { ����
PNG encoded on my Windows box: (function (exports, require, module, __filename, __dirname) { �PNG
It looks like the image is trying to be parsed as text. It looks like webpack isn't configured to handle jpg files as a part of its build. (similar issue for css-loader here: webpack/css-loader#1)
I'm looking for a solution, but I'm no WebPack expert - if anyone has any guidance, more than appreciated.
Reacted by Nive Venugopal and Nero Rodrigues Costa Luz
As default, github sends out mail updates to every partipants on new comments.
If you want to be one of them, just subscribe (the bottom to the right)!
Reacted by thevangelist, Owen Buckley and Elliot Wright
This uses the webpack/file-loader that copies the referenced assets (the jpg) to the output folder and leaves behind an URL for the browser to load.
I invite you to browse the (long) list of loaders: http://webpack.github.io/docs/list-of-loaders.html
It's quite interesting to see what other loaders are available, like the url-loader that turns the file contents into data: urls.
Reacted by Sebastian Nemeth, Werner Kvalem Vesterås and Michael Calvo
Thanks @Tragetaschen... You know what? I tried the file-loader and it failed because I set my loader to file-loader, with the '-loader' suffix like all the other loaders. I didn't notice it's actually just file.
Have just confirmed that this solves the issue:.
I've submitted a pull request #830 that adds the loader to webpack.common.js.
Just to get this right; after adding the file, loader, css files with entries like background: url('img/timeline/delete.png') no-repeat center; should not give a message like this;
Looks like ur loader is being ignored. How did u add it, can u show us the
code?
Also, check out the associated PR for a working example.
On Sat, 13 Aug 2016 at 02:26, Lars Solberg notifications@github.com wrote:
Just to get this right; after adding the file, loader, css files with
entries like background: url('img/timeline/delete.png') no-repeat center;
should not give a message like this;
the error is gone. So at least that shows that it uses my rules. I'm still learning a lot about webpack, so there might be something I am missing. But it is mostly based on angular2-webpack-starter. There are no other rules that collides. Ideas? The error is happening using the vis library.
Another observation is that I did not get any errors if I changed the loader to eg 'file123', so it for sure looks like the rule never hits. Do I need to learn webpack to handle url() in the css files?
Reacted by Julien De Coster, Rafal Baumann, Owen Buckley and oleksaz
Was looking into your issue, @xeor, and found that my fix, doesn't actually seem to fix anything.
Near as I can tell, the issue went away when I switched to using root-relative background-image url(...)... with some mixup I attributed this to using the file-loader, but so far, it seems that even if I delete these loaders it works, as long as I'm using root-relative URLs.
This is also happening to. I tried different loader for this. and finally I think there is something wrong with to-string-loader. (raw, style and so on..)
When I check the issues of to-string-loader, I got this: gajus/to-string-loader#2
Activity
[-]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl - Should be P1[/-][+]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl - Should be [/+][-]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl - Should be [/-][+]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl[/+][-]chore(webpack/styles): Backgrounds Urls not working when loaded by styles or styleUrl[/-][+]chore(webpack/styles): BUG - Backgrounds Urls not working when loaded by styles or styleUrl[/+]xeor commentedon Jul 7, 2016
I have almost the exact problem when using
'to-string-loader', 'css-loader'in webpack.Looks like this is a problem with all (most) files css loads using
url..I am using rc.4.
martaver commentedon Jul 20, 2016
I'm also experiencing this issue trying to build a project containing a component style CSS file that specifies a background url:
background: url('../assets/img/my-image.jpg') no-repeat;Not sure if this is relevant, but I've seen variations of the error line based on different images.
JPG encoded on Photoshop 3.0 (I guess?):
(function (exports, require, module, __filename, __dirname) { ����2�Photoshop 3.0JPG encoded on my Windows box:
(function (exports, require, module, __filename, __dirname) { ����PNG encoded on my Windows box:
(function (exports, require, module, __filename, __dirname) { �PNGIt looks like the image is trying to be parsed as text. It looks like webpack isn't configured to handle jpg files as a part of its build. (similar issue for css-loader here: webpack/css-loader#1)
I'm looking for a solution, but I'm no WebPack expert - if anyone has any guidance, more than appreciated.
maissani commentedon Jul 20, 2016
Without inspect more , i can say that url declaration in css files seems to be parsed as a javacript function while it's not.
slissner commentedon Jul 29, 2016
+1
LogiDesignTech commentedon Jul 29, 2016
+1
pixeltana commentedon Aug 1, 2016
+1
j4in commentedon Aug 1, 2016
👍
xeor commentedon Aug 1, 2016
Github have something called reactions, instead of
+1or thumbsupping issues. Please use it! See https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-commentsAs default, github sends out mail updates to every partipants on new comments.
If you want to be one of them, just
subscribe(the bottom to the right)!Tragetaschen commentedon Aug 1, 2016
You need to teach webpack how to handle this file type (
*.jpg). Otherwise it's assumed to be a js module.This uses the webpack/file-loader that copies the referenced assets (the jpg) to the output folder and leaves behind an URL for the browser to load.
I invite you to browse the (long) list of loaders: http://webpack.github.io/docs/list-of-loaders.html
It's quite interesting to see what other loaders are available, like the
url-loaderthat turns the file contents intodata:urls.martaver commentedon Aug 4, 2016
headbang
Thanks @Tragetaschen... You know what? I tried the file-loader and it failed because I set my loader to
file-loader, with the '-loader' suffix like all the other loaders. I didn't notice it's actually justfile.Have just confirmed that this solves the issue:.
I've submitted a pull request #830 that adds the loader to
webpack.common.js.feat: Added use of file-loader for jpg/png/gif files
maissani commentedon Aug 8, 2016
@martaver Did you miss svg format in your pull request ?
martaver commentedon Aug 9, 2016
I didn't think of it to be honest. I can add it and send another PR easily
enough.
Any other formats you think would be good to add and handle as files?
On Mon, Aug 8, 2016 at 1:00 PM Mehdi Aïssani notifications@github.com
wrote:
xeor commentedon Aug 12, 2016
Just to get this right; after adding the
file, loader,cssfiles with entries likebackground: url('img/timeline/delete.png') no-repeat center;should not give a message like this;right?
I added the file loader as works above, but I am still getting this error.. Anyone else?
martaver commentedon Aug 13, 2016
Looks like ur loader is being ignored. How did u add it, can u show us the
code?
Also, check out the associated PR for a working example.
On Sat, 13 Aug 2016 at 02:26, Lars Solberg notifications@github.com wrote:
xeor commentedon Aug 13, 2016
I have it as the PR, example;
Relevant part being..
If I change the css rule to;
the error is gone. So at least that shows that it uses my rules. I'm still learning a lot about webpack, so there might be something I am missing. But it is mostly based on angular2-webpack-starter. There are no other rules that collides. Ideas? The error is happening using the
vislibrary.Another observation is that I did not get any errors if I changed the loader to eg
'file123', so it for sure looks like the rule never hits. Do I need to learn webpack to handleurl()in the css files?martaver commentedon Aug 22, 2016
Was looking into your issue, @xeor, and found that my fix, doesn't actually seem to fix anything.
Near as I can tell, the issue went away when I switched to using root-relative background-image url(...)... with some mixup I attributed this to using the file-loader, but so far, it seems that even if I delete these loaders it works, as long as I'm using root-relative URLs.
This relates to css-loader's root relative URLs feature.
The original issue, then, is still unsolved.
A quick workaround, I guess, is to just use root-relative urls, such as:
background-image url(/assets/img/myimg.jpeg)zxx714 commentedon Aug 25, 2016
http://stackoverflow.com/questions/37402003/webpack-url-and-file-loaders-dont-working-on-angular-2-required-component-style
According to this page, exports-loader can solve this problem:
hopefulwalker commentedon Aug 29, 2016
This is also happening to. I tried different loader for this. and finally I think there is something wrong with to-string-loader. (raw, style and so on..)
When I check the issues of to-string-loader, I got this:
gajus/to-string-loader#2
13k commentedon Aug 30, 2016
looks like this is related: webpack/style-loader#55
NagRock commentedon Sep 6, 2016
@martaver thx! Workaround with /full/path/file.png works!
sparachi commentedon Sep 20, 2016
@martaver your workaround caused the error to go away but it did not load the background image. Any help would be appreciated.
@zxx714 this did not work
thescientist13 commentedon Sep 28, 2016
@martaver
This worked for me when running a development build, but not a production build.
thescientist13 commentedon Sep 30, 2016
Following the links in this SO post, using
css-to-string-loaderworked for me in the end (instead ofto-string-loader)http://stackoverflow.com/questions/38424488/webpack-css-loader-background-image-error-loading
https://www.npmjs.com/package/css-to-string-loader
feat: Added use of file-loader for jpg/png/gif files