Skip to content
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

Error: Can't find stylesheet to import (absolute path; js render; not-cli) #669

Closed
NickRimer03 opened this issue May 6, 2019 · 3 comments

Comments

@NickRimer03
Copy link

platform: Win 10 x64
version: dart-sass@1.18.0

Hello there!
I'm trying to compile this piece of code:

@import "C:\\work\\index.scss";

@each $color in $colors {
  .#{"" + $color} {
    background-color: $color;
  }
}

@each $size, $value in $sizes {
  .#{$size} {
    width: $value + px;
    height: $value + px;
  }
}

The index.scss is:

$colors: (red, green, blue);
$sizes: (
  big: 100,
  small: 50
);

And I'm sure that it is in the folder I'm looking for.

But after js build-in compile I've got this:

Error: Can't find stylesheet to import.
  ╷
2 │         @import "C:\work\index.scss";
  │                 ^^^^^^^^^^^^^^^^^^^^
  ╵

What can I do wrong? This path is very absolute.
Other sass compilation seems to be very good and suffice me,

JS piece of code:

import sass from "dart-sass";
sass.render({ data }, (err, result) => { /* */ });
@nex3
Copy link
Contributor

nex3 commented May 6, 2019

The strings you pass to @import rules are parsed the same way all CSS strings are, which means that backslashes are interpreted as escape codes rather than as literal backslash characters. This means that the import sees the string "C:workindex.scss", which is not what you intend.

My strong recommendation is to always use forward-slash-separated relative paths to refer to other stylesheets, possibly along with configured load paths so that you can access stylesheet libraries. This will provide the most portability across different systems and configurations.

If you really want to use an absolute path, though, I recommend using absolute file: URLs. In this case, you'd write @import "file:///c:/work/index.scss".

@nex3 nex3 closed this as completed May 6, 2019
@NickRimer03
Copy link
Author

@nex3 Thank you for your answer! It really helped me to recognize the problem with backslashes.
It also seems that path.replace(/\\/g, "/") works for me as well as I need.

@nex3
Copy link
Contributor

nex3 commented May 7, 2019

I strongly recommend changing your imports rather than just doing a search-and-replace on your input string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants