postcss-color-function icon indicating copy to clipboard operation
postcss-color-function copied to clipboard

Unable to parse color from string "$primary-color"

Open martenzander opened this issue 6 years ago • 6 comments

I am using postcss-advanced-variables and if i try to put variables into my color values I get the following error:

Unable to parse color from string "$primary-color"

this is my postcss line up:

    'postcss-import': {},
	'postcss-at-rules-variables' : {},
	'postcss-nested-ancestors' : {},
	level4 : {},
	'postcss-for' : {},
	'postcss-each' : {},
	'postcss-sassy-mixins' : {},
	'postcss-advanced-variables' : {},
	'postcss-conditionals' : {},
	'postcss-hexrgba' : {},
	'postcss-object-fit-images' : {},
	'postcss-flexbugs-fixes' : {},
	'postcss-quantity-queries' : {},
	'postcss-size' : {},
	'postcss-will-change' : {},
	'postcss-nested' : {},
	'postcss-easings' : {},
	'postcss-random' : {},
	'postcss-calc' : {
		warnWhenCannotResolve: false,
		mediaQueries: true,
	},
	'postcss-inline-svg' : {
		path: 'src/svg',
		encode: function encode(code) {
		    return code
		        .replace(/%/g, '%25')
		        .replace(/</g, '%3C')
		        .replace(/>/g, '%3E')
		        .replace(/&/g, '%26')
		        .replace(/#/g, '%23');
		},
		removeFill: true,
	},
	'postcss-initial' : {},
	autoprefixer : { browsers },
	'postcss-color-function' : {},
	cssnano : ctx.env === 'production' ? {
		filterPlugins: false,
		safe: true,
		mergeRules: false,
		browsers,
		discardComments: {
			removeAll: true,
		},
	} : false,

martenzander avatar Aug 02 '17 12:08 martenzander

@SlimMarten could you remove all plugins except postcss-advanced-variable and postcss-color-function and provide css code when it error reproduced?

Semigradsky avatar Nov 03 '17 08:11 Semigradsky

Was there a resolution to this?

When I try to do this:

 --dark-base: #1b1c20;
 --dark-10: color(var(--dark-base) lightness(10%));

I get this output: image

but the color doesnt take.

If I use the color directly instead of the var, i.e. #1b1c20; it works but I'm obviously duplicating..I'm using React Starter Kit.

damiangreen avatar Aug 13 '18 12:08 damiangreen

bump

marr avatar Jan 10 '19 01:01 marr

bump! Edit: Of note, it looks like there was discussion a while back around postcss-custom-properties, but using that plugin is not resolving the issue for me :/ https://github.com/postcss/postcss-color-function/issues/25

bkincart avatar Sep 16 '21 15:09 bkincart

bump

rostik32 avatar Nov 19 '22 19:11 rostik32

As a replacement using postcss-functions plugin with css-color-function npm package (which is used under the hood of postcss-color-function)

Webpack config:

var color = require('css-color-function');

...

{
    loader: 'postcss-loader',
    options: {
        postcssOptions: {
            plugins: [
                [
                    'postcss-functions',
                    {
                        functions: {
                            color: (value) => color.convert(`color(${value})`)
                        }
                    }
                ]
            ]
        }
    }
}

abelozerov avatar Apr 10 '23 13:04 abelozerov