parcel: Relative path images of SASS @import is not supported
Choose one: this is a 🐛 bug report.
💻 Code Sample
main.scss
@import '../components/topbar/index.scss';
topbar/index.scss
.topbar {
height: 60px;
background: #f60 url("./play.png") repeat;
font-size: 2em;
}
🤔 Expected Behavior
main.css
.topbar {
height: 60px;
background: #f60 url("md5xxxxxxx.png") repeat;
font-size: 2em;
}
😯 Current Behavior
main.scss: Cannot resolve dependency './play.png'
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.4.1 |
| Node | 8.6.0 |
| npm/Yarn | npm |
| Operating System | macOS 10.12.6 |
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 8
- Comments: 26 (4 by maintainers)
Hello, I had a similar problem with this kind of import
@import '../node_modules/@ibm/plex/scss/ibm-plex.scss';,got solved by wrapping it with
url()@import url('../node_modules/@ibm/plex/scss/ibm-plex.scss');Thanks!
I’ve been getting around it importing media, ie:
And then inserting those where necessary with js. Not sure if that’s of any help @spion
try this way
import './main.scss' // main.jsI’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.
@petrmiko thanks .lessrc works for me.
I have experimental support for relativeUrls for SASS in my fork https://github.com/spion/parcel (by adding “relativeUrls”: true in
.sassrc. Its really hacky though due to https://github.com/sass/node-sass/issues/2223Will 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’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 (
woff,ttf, etc) can’t be resolved.This is rather frustrating. I can include the pre-built CSS files in my
index.htmllike:But that means I can’t do anything to customize the way that file is compiled, such as change
$fa-css-prefixor any of the other configurable options this package makes available. And when you include the pre-built CSS file, Parcel has no issue finding those resources and copying them to dist and such, but for SASS it seems to just get lost.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.
We would need to process
url()before SASS is run (similar to https://github.com/bholloway/resolve-url-loader):--no-sourcemaps)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
@importpaths 🤔For less I am using .lessrc file in project root with content
{ relativeUrls: true, }Until I did that (by trial and error), I faced the same issue with relative path to a image. Maybe the same could help you (if there’s something like .sassrc)