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

Undefined variable $ with postcss-each #98

Closed
anlijiu opened this issue Mar 4, 2021 · 4 comments
Closed

Undefined variable $ with postcss-each #98

anlijiu opened this issue Mar 4, 2021 · 4 comments

Comments

@anlijiu
Copy link

anlijiu commented Mar 4, 2021

example :

@each $name, $weight in (thin, ultralight, light, regular, medium, semibold, bold, extrabold, heavy),
(100, 200, 300, 400, 500, 600, 700, 800, 900)
{
.font-$name {
font-family: 'lc-gilroy';
font-weight: $weight;
}
}

Undefined variable $name

@sampullman
Copy link
Collaborator

postcss-each has an interesting way of solving this, you can use their afterEach option like so:

require('postcss-each')({
  plugins: {
    afterEach: [
      require('postcss-simple-vars')
    ]
  }
})

It would be better if this can be resolved more gracefully via #12, though.

@anlijiu
Copy link
Author

anlijiu commented Mar 5, 2021

same error.
Dependency:
"postcss-simple-vars": "^6.0.3",
"postcss-each": "^1.0.0"

postcss.config.js sequence:

require('postcss-each')({
  plugins: {
    afterEach: [
      require('postcss-simple-vars')
    ] 
  } 
}), 
require('postcss-simple-vars')(),

If I change postcss-simple-vars index.js line 178
from "if (node.name === 'define-mixin') {"
to “if (node.name === 'define-mixin' || node.name === 'each') {”
it works .

but i still can't do this:

$some-variants: (thin, ultralight, light, regular, medium, semibold, bold, extrabold, heavy), (100, 200, 300, 400, 500, 600, 700, 800, 900);
@each $name, $weight in $some-variants
{
  .font-$name {
    font-family: 'lc-gilroy';
    font-weight: $weight;
  }
}

@sampullman
Copy link
Collaborator

Sorry for the lack of clarification, if I understand the postcss-each code correctly, you need to remove the second require('postcss-simple-vars')() (it should only be in the afterEach plugin).

@anlijiu
Copy link
Author

anlijiu commented Mar 5, 2021

I setup a clean repo only include 'postcss-simple-vars' and 'postcss-each' ,then every thing works fine

so I guess may be other plugin cause the problem.

Thank you for your reply !

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