question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error resolving root-relative image paths in css for external images

See original GitHub issue

Bug report

What is the current behavior?

When encountering a root-relative url (IE: url(/path/to/image.jpg) ) in css, Webpack attempts to process the asset and throws an error if it fails to do so.

This is fine if the image is local to the repository, or otherwise available at build-time. But if the image is expected to come from another service, the build will fail.

If the current behavior is a bug, please provide the steps to reproduce.

Including this rule in a css class will cause this to happen:

background-image: url(/path/to/image.jpg);

I reproduced the issue in this repo .

Adding this Webpack magic-comment fixes it for dev but not production: /* webpackIgnore: true */

Correction:

The magic-comment works for css files in production, but not for sass files.

Either way; you should not need magic-comments to make this basic functionality work

What is the expected behavior?

Webpack should leave the path as is and not attempt to process the asset. This worked well in Webpack 4.

Other relevant information: webpack version: 5.64.4 Node.js version: 17.6.0 Operating System: Ubuntu Linux Additional tools:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
dovidweiszcommented, Mar 10, 2022

Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Angular CLI and unable to use relative image paths in ...
Using Angular CLI and unable to use relative image paths in CSS files ; Did you trying loading the image like url('./images/image.png')? – ......
Read more >
Relative paths to images in CSS doesn't work anymore (ie ...
Hi I can't load image from CSS, I'm using this: background-image: url('../images/backgrounds/footer-bg-1.jpg'); but I get error ERROR Failed ...
Read more >
How to fix CSS background-image not working | HTML/CSS
Working with background images in CSS can be tricky. ... The path needs to be relative to where your HTML file is. If...
Read more >
Background Image URL...not working on all pages - MSDN
Use external .css file and set the image path relative to this file; Use ASP.NET ~ symbol for the app root path; Use...
Read more >
css-loader | webpack - JS.ORG
To import assets from a node_modules path (include resolve.modules ) and for alias , prefix ... Don't handle images under root-relative /external_images/ if ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found