Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sass "Error: Can't find stylesheet to import."

Tags:

css

sass

I'm running into an issue which seems similar to the one reported in https://github.com/sass/dart-sass/issues/284, but doesn't seem 'fixed' for me. I'm trying to follow the workflow described in https://getbootstrap.com/docs/4.1/getting-started/theming/ to import Bootstrap's SCSS source code.

Here is my (simplified) directory structure:

.
├── index.html
├── node_modules
│   ├── @mdi
│   └── bootstrap
├── package-lock.json
├── package.json
├── scss
│   └── peek-solutions2.scss
└── stylesheets
    └── peek-solutions.css

I've installed Bootstrap using npm install bootstrap; my package.json contains the following dependencies:

{
  "dependencies": {
    "@mdi/font": "^2.2.43",
    "bootstrap": "^4.1.1"
  }
}

In peek-solutions2.scss, I've added the following line:

@import "../node_modules/bootstrap/scss/bootstrap";

I've tried the sass --watch command specifying input and output files in different directories (cf. https://sass-lang.com/guide), but I run into an import error:

Kurts-MacBook-Pro:peek-solutions2 kurtpeek$ sass --watch scss/peek-solutions2.scss:stylesheets/peek-solutions2.css
Error: Can't find stylesheet to import.
@import "functions";
        ^^^^^^^^^^^
  ../node_modules/bootstrap/scss/bootstrap.scss 8:9  @import
  scss/peek-solutions2.scss 1:9                      root stylesheet

Sass is watching for changes. Press Ctrl-C to stop.

It seems like this is a path issue; _functions.scss is in the same directory as bootstrap.scss in node_modules/bootstrap/scss, but it seems like the sass command is expecting it to be in my custom scss directory. How can I fix this?

like image 328
Kurt Peek Avatar asked Jul 01 '18 21:07

Kurt Peek


People also ask

Can you import CSS into Sass?

scss files, Sass can import plain old . css files. The only rule is that the import must not explicitly include the . css extension, because that's used to indicate a plain CSS @import .

Is Sass compatible with SCSS?

It makes use of semicolons and brackets like CSS (Cascaded Style Sheets). SASS and SCSS can import each other. Sass actually makes CSS more powerful with math and variable support. Let's list down the main difference between SASS and SCSS.

Is Sass import deprecated?

As of October 2021 @import will be deprecated, along with global built-in functions, and one year after that (no later than October 2022) @import support will be dropped. Make sure you go check out the newly refreshed Sass documentation for the latest updates.

What is @import in Sass?

Sass Importing Files The @import directive allows you to include the content of one file in another. The CSS @import directive has a major drawback due to performance issues; it creates an extra HTTP request each time you call it.


3 Answers

just delete the dots in the beginning , you must write:

@import "node_modules/bootstrap/scss/bootstrap";

in your scss file

like image 183
adjaout Avatar answered Oct 21 '22 03:10

adjaout


This happened to me because I was running ng build --prod within a folder other than the root project folder, and every other css import breaks.

The solution is to cd to the root folder.

like image 18
Kisinga Avatar answered Oct 21 '22 03:10

Kisinga


I solved it by using an extra forward slash @import "//abstracts/variable";

like image 11
Rene Morales Avatar answered Oct 21 '22 04:10

Rene Morales