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.

LESS is not re-writing relative paths in url() when importing.

See original GitHub issue

One trivial application of lessc is that it will concatenate several .less files into one .css file via the use of @import.

However, if one of the @imported files is in a subdirectory, and uses a url() to refer to an image in the subdirectory, the url() is not rewritten in the concatenated output.

For example, consider these files: a.jpg lib/b.jpg lib/bottom.less top.less

top.less looks like: @import “lib/bottom.less”;

.top_a { background-image: url("a.jpg");}
.top_b { background-image: url("lib/b.jpg");}

bottom.less looks like: .bottom_a { background-image: url(“…/a.jpg”);} .bottom_b { background-image: url(“b.jpg”);}

Actual output of less top.less: .bottom_a { background-image: url(“…/a.jpg”); } .bottom_b { background-image: url(“b.jpg”); } .top_a { background-image: url(“a.jpg”); } .top_b { background-image: url(“lib/b.jpg”); }

Problem is that .bottom_a and .bottom_b have url()s that don’t point correctly to their images.

Desired output:

.bottom_a {
  background-image: url("a.jpg");
.bottom_b {
  background-image: url("lib/b.jpg");
.top_a {
  background-image: url("a.jpg");
.top_b {
  background-image: url("lib/b.jpg");

Issue Analytics

  • State:closed
  • Created 13 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

mendrikcommented, Apr 6, 2011

The whole path management seems to be one big pile of shit. My hate for this has grown to a raging fire that burns with the fierce passion of a million suns. Whenever I try to use subdirectories in @import, either the production build fails, the local server execution or the local file system. Why does this crap try to locate styles inside the build base directory? It should be always relative to the parent less file.

lukeapagecommented, Sep 1, 2012

There is a lot of confusion here, but I think this is basically #331 - asking for node lessc to alter relative paths. will handle browser specific issues seperately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative URL not working in .less - Stack Overflow
This import location will be relative to the module. How can I resolve this ? I want to reference fonts from current directory...
Read more >
Pure CSS @import with relative path fails [#2584185] - Drupal
I think Drupal core's url rewriting for CSS @import's requires it to be wrapped in url(), not 100% sure as this is the...
Read more >
Documentation - Module Resolution - TypeScript
A non-relative import can be resolved relative to baseUrl , or through path mapping, which we'll cover below. They can also resolve to...
Read more >
Relative path in css for @font-face embedding - Google Groups
I'm trying to use an embedded font referenced in a stylesheet. The only url that seems to work in the @font-face declaration (in...
Read more >
Static Asset Handling - Vite
The difference is that the import can be either using absolute public paths (based on project root during dev) or relative paths. url()...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found