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

Comments and "@import must precede all other statements" #163

Closed
Dylan-Chapman opened this issue Jan 27, 2016 · 10 comments · Fixed by #164
Closed

Comments and "@import must precede all other statements" #163

Dylan-Chapman opened this issue Jan 27, 2016 · 10 comments · Fixed by #164

Comments

@Dylan-Chapman
Copy link

This CSS:

@import "helpers";


/* ============================================================================
   BASE STYLING
   ============================================================================ */

@import "base/reset";

@import "base/typography";
...

Produces this error (for the second @import statement):

@import must precede all other statements (besides @charset)

This is kicked because of the comment. This shouldn't be the case though, should it?

@TrySound
Copy link
Member

Thanks for your report. Will fix asap

@TrySound
Copy link
Member

@Dylan-Chapman Use please postcss-import@7 until fix.

@Dylan-Chapman
Copy link
Author

Will do. Appreciate it!

@MoOx
Copy link
Contributor

MoOx commented Jan 27, 2016

8.0.2 released

@Paulmicha
Copy link

Something doesn't seem right : before, when using https://github.com/MoOx/gulp-cssnext, I could use @custom-media statements before the first @import, ex :

@charset "UTF-8";
@custom-media --wide (min-width:81.25rem);
@import "sanitize.css";
@import "suitcss-components-flex-embed";
@import "./base/_typography.vars.css";
...

Now, it yields @import must precede all other statements (besides @charset) - BUT : only the first @import fails - all the others pass.

What is making this a blocking issue, though, is the fact that when I move all @custom-media statements after the first import, I get errors like variable '--line-height' is undefined and used without a fallback.

Current workaround : I'm forced to duplicate the first @import to get back on track.

@MoOx
Copy link
Contributor

MoOx commented Feb 14, 2016

FYI, @custom-media --wide (min-width:81.25rem); can be defined after even if imported files use it. It's how CSS works.

@Paulmicha
Copy link

Good to know.

It doesn't explain, however, the rest of unrelated errors - the undefined variables - when I had moved these declarations after the first @import (and left a few after), which seemed to indicate a much more worrying issue - that the order of inclusion could not be guaranteed.

But, after moving all @custom-media after the very last @import, no more errors \o/

Thanks for the feedback :)

@MoOx
Copy link
Contributor

MoOx commented Feb 14, 2016 via email

@Paulmicha
Copy link

Yes.

This error made me look into https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#nested_statements (from https://developer.mozilla.org/en/docs/Web/CSS/@import), which clarifies the existence of such a restriction in the position of these statements - in case anyone else was wondering.

@TayyabMirza
Copy link

Putting all imports at the beginning of the file, css below the imports fix this issue.

@postcss postcss locked as resolved and limited conversation to collaborators Dec 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants