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

Cannot use simple vars value for setting CSS variable #109

Open
winston0410 opened this issue Oct 13, 2021 · 5 comments
Open

Cannot use simple vars value for setting CSS variable #109

winston0410 opened this issue Oct 13, 2021 · 5 comments

Comments

@winston0410
Copy link

I tried to set simple vars as CSS variable, but it doesn't work:

$blue:   #056ef0;

:root{
  --color: $blue;
}

It will gives an error like this:

Syntax Error: SyntaxError                                                      friendly-errors 20:24:33

(1:1) <css input> Unknown word

> 1 | $blue
    | ^

Is this by design?

@ai
Copy link
Member

ai commented Oct 13, 2021

  1. What PostCSS plugins do you use?
  2. Show the full track trace of the error.

@bahtou
Copy link

bahtou commented Nov 10, 2021

may be related:

Copy/Paste the example

$dir:    top;
$blue:   #056ef0;
$column: 200px;

.menu_link {
  background: $blue;
  width: $column;
}
.menu {
  width: calc(4 * $column);
  margin-$(dir): 10px;
}

I get this error:

ERROR in ./components/Footer/styles.css (../node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[3].use[1]!../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[3].use[2]!./components/Footer/styles.css)
Module build failed (from ../node_modules/postcss-loader/dist/cjs.js):
SyntaxError

(17:3) postcss-simple-vars: ./components/Footer/styles.css Undefined variable $dir

  15 |   width: $column;
  16 |   width: calc(4 * $column);
> 17 |   margin-$(dir): 10px;
     |   ^
  18 | }
  19 |

Here is my postcssrc.json

module.exports = {
  "plugins": [
    "postcss-import",
    "postcss-map-get",
    "postcss-mixins",
    "postcss-hexrgba",
    "postcss-simple-vars",
    "precss",
    "postcss-preset-env",
    "autoprefixer"
  ]
};

@ai
Copy link
Member

ai commented Nov 10, 2021

Here is my output (without any error):

.menu_link {
  background: #056ef0;
  width: 200px;
}
.menu {
  width: calc(4 * 200px);
  margin-top: 10px;
}

@bahtou
Copy link

bahtou commented Nov 10, 2021

went through the plugins adding/removing

when precss is enabled as a plugin along with postcss-simple-vars the error pops up

Seems like precss uses postcss-advanced-variables these plugins might be colliding 🤔

@ai
Copy link
Member

ai commented Nov 10, 2021

@bahtou yeap. I recommend replacing precss since it is not maintained well with separated plugins

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

3 participants