Skip to content

TypeError in './lib/resolve-value.js' when the value of css-variable is not of string type. #83

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

Closed
shonie opened this issue Sep 7, 2018 · 4 comments
Assignees
Labels

Comments

@shonie
Copy link
Contributor

shonie commented Sep 7, 2018

Hello!

I use your great package with this postcss.config.

I pass plain javascript object with variables to option variables. But if any variable is set to not-string value build process crashes with this TypeError.

screen shot 2018-09-07 at 1 49 37 pm

I've created reproduce repo here.

You can do:

git clone https://github.com/shonie/postcss-css-variables-bug-reproduce.git

npm i

npm start

Can i create PR for fixing this?

@MadLittleMods
Copy link
Owner

@shonie PR welcome (add some tests)! 🙂

@shonie
Copy link
Contributor Author

shonie commented Sep 9, 2018

Thank you for your response!

But before rushing into implementation, i want to discuss solution with you. I can propose two methods of fixing this.

Simplest one is to cast each variable value to string, which is safe, but not transparent.

Other, and, on my opinion better one, is to validate plugin options by some validations tool (something like schema-utils or ajv.

Me, personally, like schema-utils as it most likely to be already in client's node_modules as webpack uses it under the hood.

Thank you.

@shonie
Copy link
Contributor Author

shonie commented Sep 9, 2018

I have just now realized that ajv is strict dependency of schema-utils 😄. So better to use ajv directly.

@MadLittleMods
Copy link
Owner

@shonie Casting to string seems reasonable. We already do it for undefined -> 'undefined', #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants