-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative path images of SASS @import is not supported #540
Comments
Seeing the same issue using vue's |
I have experimental support for relativeUrls for SASS in my fork https://github.com/spion/parcel (by adding "relativeUrls": true in Will try submitting a PR once I have tests... but in the meantime, just wondering, anyone has an idea about a better way to do this? |
I've been getting around it importing media, ie: import audio from './song.mp3'
import bgImage from './bg_image.jpg'
import someLogo from './logo.png' And then inserting those where necessary with js. Not sure if that's of any help @spion |
try this way |
I'm having a similar issue with Vue. Not sure if related to this one. In my main body {
background-image: url('../assets/test.jpg');
} However, when trying to do the same from inside a component I cannot get the image to display from CSS. So this works when trying to reach the image in the template of the Vue component:
But this doesn't work:
And I get this error in the browser:
Edit: Sorry for polluting this issue. I was using |
I use *.scss file also produce the same problem, the path of image file can not be found correctly |
For less I am using .lessrc file in project root with content
|
I think there isn't really a clean way of achieving this. (After looking through the tracking issue on node-sass and some PRs that should help resolve this) |
@petrmiko thanks .lessrc works for me. |
like #2199 |
I created an example stating the issue: https://github.com/jussikinnula/sass-url-issue-with-imports Basically we would need similar as |
@jussikinnula there is a fix for the issue (in this branch https://github.com/spion/parcel) although it's kinda hacky. But nobody has implented it in the master yet. SASS currently doesn't support this yet, so this is probably the only way to do this. |
Thanks @DeMoorJasper, if I need to use Parcel I'll use that as workaround. At the moment in project I'm working on I just switched from Parcel to Webpack, and used |
@jussikinnula I didn't make the fix @spion did, and it's also using a very outdated version of Parcel, so I wouldn't recommend it. I however do recommend someone to make a PR with a similar fix |
Hello, I had a similar problem with this kind of import
got solved by wrapping it with
Thanks! |
This doesn't only happens for images. Recently I tried to setup Font Awesome 5 with web fonts.
Fonts are being copied to the output directory root, however Parcel fails to resolve a correct path for them. I'm really confused about Parcel because anything more than basic setup simply doesn't work: CSS modules and now invalid |
Don't |
We would need to process
|
This method helped me
Write inside brackets data-url: |
is this issue resolved? I'm having the same problem. I tried @mukhammed3's resolution but that doesn't work for me. I also tried using '~' at the beginning of my url but same issue occurs. The compiled url in my css file by sass is the same as if it was in my home.scss file. Here is my folder structure:
as you can see here my styles.css is referencing the background.png like in my home.scss. It works on my page but when I use Parcel it detects the wrong path of my background.png from my css file. |
I'm also having this problem and can't tell from this thread if there's a viable work around? Wanting to use self hosted fonts can't be that unusual. |
…ed font due to relative path parcel issue: parcel-bundler/parcel#540
I'm not even sure what the designed behavior is. I have a separate compilation step that copies the needed assets to specific locations. I put the correct path in the |
I'm also running into this issue attempting to import fonts from NPM packages. I can import the SASS file for the font definition, but the paths to the actual font files (
This is rather frustrating. I can include the pre-built CSS files in my <link rel="stylesheet" href="node_modules/@fortawesome/fontawesome-pro/css/regular.min.css" type="text/css"> But that means I can't do anything to customize the way that file is compiled, such as change |
any updates or workarounds on that? I have the same issue. |
Thanks! |
I've found a partial work-around for fonts. @import "@fontsource/roboto/400.css"; In Sass, this will fail. It will correctly locate the module that I'm referencing, but it will fail to resolve the paths to all the fonts that this stylesheet uses and it will error out as if it were looking for the fonts in the local directory rather than relative to the module. However, if I do this in CSS: @import "npm:@fontsource/roboto/400.css"; It works correctly! Furthermore, if I import my CSS file into my Sass file, it also works just fine. So I created a I'm not entirely sure if this can be utilized to fix issues that others were having with images, but it goes to demonstrate that Parcel is more than capable of doing this correctly, but for some reason is tripping up in the specific case of Sass imports. I'm assuming that in this case, it works because it's resolving the entire CSS file first before importing it into Sass. This of course doesn't fully fix the issue, but it does at least let all the CSS get bundled into one file now. |
Choose one: this is a 🐛 bug report.
💻 Code Sample
main.scss
topbar/index.scss
🤔 Expected Behavior
main.css
😯 Current Behavior
🌍 Your Environment
The text was updated successfully, but these errors were encountered: