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: Import directives may not be used within control directives or mixins. #1724

Closed
saper opened this issue Nov 12, 2015 · 9 comments
Closed

Comments

@saper
Copy link
Member

saper commented Nov 12, 2015

Reported on gitter by @safareli

Input file:

@mixin import-google-fonts() {
  @import url("http://fonts.googleapis.com/css?family=#{$family}");
}
$family: unquote("Droid+Sans");
@include import-google-fonts();

Works for Ruby Sass, libsass fails with:

Error: Import directives may not be used within control directives or mixins.
        on line 2 of spec/misc/todo_import_in_mixin/input.scss
>>   @import url("http://fonts.googleapis.com/css?family=#{$family}");
   --^
.
Expected: 1
  Actual: 0

4 runs, 12 assertions, 4 failures, 0 errors, 0 skips

Used

sassc: 3.3.0
libsass: 3.3.2
sass2scss: 1.0.5

saper added a commit to saper/sass-spec that referenced this issue Nov 12, 2015
Error: Import directives may not be used within control directives or mixins.

sass/libsass#1724
@safareli
Copy link

+1

@xzyfer
Copy link
Contributor

xzyfer commented Nov 13, 2015

Spec added sass/sass-spec#602

@xzyfer xzyfer added this to the 3.3.3 milestone Nov 13, 2015
@unfulvio
Copy link

+1

@harryfinn
Copy link

@saper this error is also present when trying to @import "local/file"; (local import rather than from external url) - is there something in place to also allow this with libsass or an accepted current limitation of @import for local files?

@xzyfer
Copy link
Contributor

xzyfer commented May 26, 2016

This error isn't about what you're importing, but where you're importing. The error is telling you that you cannot use @import inside a mixin or control directives like @if/@else/@for/@each etc..

@harryfinn
Copy link

harryfinn commented May 26, 2016

@xzyfer from what I understand of the associated PR's above, PR #1848 allows the use of @import within control directives for libsass, bringing it inline with ruby sass, or have I got that wrong?

I've just tried @saper's code in my libsass powered project and it now works having updated my version of node-sass (which I assume therefore includes the fixes in PR #1848) however, when I amend the code to use a local file it fails again

@xzyfer
Copy link
Contributor

xzyfer commented May 26, 2016

This is a tricky issue, and one that LibSass doesn't get 100% correct. Technically there are two kinds of imports, Sass imports and CSS imports. What kind of import an @import is depends on what you're importing.

If you're obviously importing another Sass files then it's a Sass import. Sass imports are not allowed in mixins and control directives. This is the case you're running into so the error is correct.

If you're importing something from an URL or file with a .css extension then it's a CSS import, and it can be used in mixins and control directives.

This bug was regarding us incorrectly erring when CSS import (because it's a remote font url) is used in a mixin. Unfortunately it appeats this behaviour has once again broken.

@harryfinn
Copy link

@xzyfer Ah that make sense then, thanks for the explanation!

@xzyfer
Copy link
Contributor

xzyfer commented May 26, 2016

I've created an issue for tracking the regression in #2096

@HamptonMakes HamptonMakes changed the title Error: Import directives may not be used within control directives or mixins. [$100] Error: Import directives may not be used within control directives or mixins. [$100 awarded] Nov 3, 2016
@HamptonMakes HamptonMakes changed the title Error: Import directives may not be used within control directives or mixins. [$100 awarded] Error: Import directives may not be used within control directives or mixins. Jan 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants