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.

Angular CLI 1.5.x to 1.6.6 breaks build with relative image url ~ *.scss (tilde)

See original GitHub issue

Hi,

[x] Support [x] Potential bug

I’ve googled and searched through a lot of GitHub issues. But can’t find what I’m looking for… so please bear with me 😉

folder structure:

/project/frontend
/project/frontend/src
/project/frontend/dist
/project/frontend/node_modules
/project/frontend/src/app
/project/frontend/src/assets
/project/frontend/src/scss

I want to make a relative path to my image (located in assets) from my stylesheets (located in src/scss)… I used to do:

.server-response-404{
  @include retina-background-image('~assets/images/404', 'jpg');
}

Now with 1.6.6 I can’t use tilde… When I run ‘npm start’ or ‘ng serve’ I get this error

ERROR in ./node_modules/css-loader?{"sourceMap":false,"import":false}!./node_modules/postcss-loader/lib?{"ident":"postcss","sourceMap":false}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":false,"precision":8,"includePaths":[]}!./src/scss/main.scss
Module not found: Error: Can't resolve './assets/images/404.jpg' in '/Users/username/project/frontend/src/scss'
resolve './assets/images/404.jpg' in '/Users/username/project/frontend/src/scss'
  using description file: /Users/username/project/frontend/package.json (relative path: ./src/scss)
    Field 'browser' doesn't contain a valid alias configuration

...
/Users/username/project/frontend/src/scss/assets/images/404.jpg doesn't exist

Question:

So how do I make a relative path - relative to the css file - to my images?

When I remove the tilde, ‘npm start’ can build … but the image is not showing up in the html.

Please keep in mind that my production and local folder structures are different, thats why it needs to be relative to the css file.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
szabototo89commented, Mar 21, 2018

This is a serious breaking change, it cannot be closed by just saying that use relative paths. There is a reason why I used ~ in the SCSS stylesheets.

2reactions
bnusseycommented, Feb 7, 2018

Hi @filipesilva I think this should be reopened and addressed as its a serious bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Angular CLI and unable to use relative image paths in ...
json and define the path relatively, the build still fails, not finding the ressources url('someRelativeLink') . I used a work around and put...
Read more >
Using Sass with the Angular CLI - DigitalOcean
Use the ~ to import Sass files in Angular CLI projects. ... Create a new project with Sass with the following:
Read more >
Simple adding of image not working with relative url path
I feel like a real stooge not being able to figure this out, but why does a simple line like the following render...
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