Can't properly configure PostCSS Autoprefixer for npm project

Hi everyone!

I’m trying to configure PostCSS Autoprefixer but it doesn’t work. It should output new style.prefix.css file in the same ‘css’ folder where input style sheet is located. Can anyone help me understand, what is wrong with my npm script/setup?
I’ve been googling and trying different commands for few hours without any luck…
edit: I’m using Windows 8.1 machine

Here is my package.json

{
  "name": "sb-demo-website",
  "version": "1.0.0",
  "description": "demo website",
  "main": "index.js",
  "scripts": {
    "sass": "node-sass-chokidar sass/main.scss css/style.css -w --recursive --skip-initial",
    "compile-sass": "node-sass-chokidar sass/main.scss css/style.comp.css",
    "prefix-css": "postcss css/style.comp.css -o css/style.prefix.css --use autoprefixer"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "tk",
  "license": "ISC",
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "browserslist": "last 3 versions",
  "devDependencies": {
    "autoprefixer": "^10.0.0",
    "node-sass": "^4.14.1",
    "node-sass-chokidar": "^1.5.0",
    "postcss": "^8.0.5",
    "postcss-cli": "^7.1.2"
  }
}

and here is output when I run my script:

$ npm run prefix-css

> sb-demo-website@1.0.0 prefix-css C:\Users\tk\Documents\Study\web\css\demo1
> postcss css/style.comp.css -o css/style.prefix.css --use autoprefixer

Error: PostCSS plugin autoprefixer requires PostCSS 8. Update PostCSS or downgrade this plugin.
    at Processor.normalize (C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\node_modules\postcss\lib\processor.js:167:15)
    at new Processor (C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\node_modules\postcss\lib\processor.js:56:25)
    at postcss (C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\node_modules\postcss\lib\postcss.js:55:10)
    at C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\index.js:216:14
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sb-demo-website@1.0.0 prefix-css: `postcss css/style.comp.css -o css/style.prefix.css --use autoprefixer`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sb-demo-website@1.0.0 prefix-css script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\tk\AppData\Roaming\npm-cache\_logs\2020-09-18T17_50_55_597Z-debug.log

Thanks for your help!

1 Like

Ok, I found answer by myself :slight_smile:
Turns out latest autoprefixer v10.0.0 has some bugs and doesn’t work well with postcss-cli. Downgrading it to previous version 9.8.6 fixed the problem

Hi,
Im going through the same issue , would please tell me how did you downgraded it ?

Hi,
Sorry for the late reply. Hopefully you’ve already managed to google how to do this. If not, you can downgrade your package by just installing specific version - it will replace the current one:
npm i autoprefixer@9.8.6