Error: postcss received undefined instead of css string

Error: postcss received undefined instead of css string

This error occurs when using PostCSS but passing undefined as the CSS string value instead of an actual CSS string. PostCSS is a tool for transforming styles with JavaScript plugins, and it requires valid CSS input to work correctly.

Example 1:


import postcss from 'postcss';
import autoprefixer from 'autoprefixer';

const css = undefined;

postcss([autoprefixer])
  .process(css)
  .then(result => {
    console.log(result.css);
  });
  

In the above example, the variable “css” is assigned the value of undefined. When we try to process it with PostCSS, the error occurs since PostCSS expects a valid CSS string for transformation.

Example 2:


import postcss from 'postcss';
import autoprefixer from 'autoprefixer';

const css = '.example { color: red; }';

postcss([autoprefixer])
  .process(css)
  .then(result => {
    console.log(result.css);
  });
  

In this example, the variable “css” is assigned a valid CSS string “.example { color: red; }”. When processed with PostCSS, it will apply the autoprefixer plugin and transform the CSS accordingly.

Read more interesting post

Leave a comment