Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostCSS error: [object Object] is not a PostCSS plugin

Tags:

The error is coming from the postcss plugin, I think I may have written it incorrectly.

I'm trying to add cssnano and autoprefixer to the postcss plugin.

gulp/node_modules/gulp-postcss/node_modules/postcss/lib/processor.js:143         throw new Error(i + ' is not a PostCSS plugin');         ^  Error: [object Object] is not a PostCSS plugin     at Processor.normalize (/Applications/XAMPP/xamppfiles/htdocs/sites/gulp/node_modules/gulp-postcss/node_modules/postcss/lib/processor.js:143:15)     at new Processor (/Applications/XAMPP/xamppfiles/htdocs/sites/gulp/node_modules/gulp-postcss/node_modules/postcss/lib/processor.js:51:25)     at postcss (/Applications/XAMPP/xamppfiles/htdocs/sites/gulp/node_modules/gulp-postcss/node_modules/postcss/lib/postcss.js:73:10)     at Transform.stream._transform (/Applications/XAMPP/xamppfiles/htdocs/sites/gulp/node_modules/gulp-postcss/index.js:47:5)     at Transform._read (_stream_transform.js:167:10)     at Transform._write (_stream_transform.js:155:12)     at doWrite (_stream_writable.js:300:12)     at writeOrBuffer (_stream_writable.js:286:5)     at Transform.Writable.write (_stream_writable.js:214:11)     at DestroyableTransform.ondata (/Applications/XAMPP/xamppfiles/htdocs/sites/gulp/node_modules/gulp-sass/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:531:20) Mac-a45e60e72dad:gulp JoeKonst$  

My code:

// Dependancies var gulp = require('gulp'),     browserSync = require('browser-sync'),     plumber = require('gulp-plumber'),     autoprefixer = require('gulp-autoprefixer'),     uglify = require('gulp-uglify'),     compass = require('gulp-compass'),     rename = require('gulp-rename'),     nano = require('cssnano'),     del = require('del'),     postcss = require('gulp-postcss'),     sass = require('gulp-sass');  // Styles gulp.task('styles', function(){     gulp.src('sass/main.scss')     .pipe(sass())     .pipe(postcss([autoprefixer({browsers: ['last 2 versions']}), nano()]))     .pipe(gulp.dest('css/'));      gulp.watch('sass/**/*.scss', ['styles']); });  // Tasks gulp.task('default', ['styles']); 
like image 296
Joe Consterdine Avatar asked Oct 17 '16 15:10

Joe Consterdine


People also ask

How do I add plugins to PostCSS?

In the root directory of your project, create a file and name it postcss. config. js. Inside the plugins array, we add our plugins.

What is PostCSS plugin?

PostCSS is a tool for transforming CSS with JavaScript plugins. It provides features via its extensive plugin ecosystem to help improve your CSS writing experience. You can pick the plugins you need or even write a custom one for yourself.

Can I use PostCSS with SCSS?

The most common way to integrate PostCSS into your current workflow, if you're already using Sass, is to pass the compiled output of your . sass or . scss file through PostCSS and its plugins. This will generate another CSS file that has the output of both Sass and PostCSS.


1 Answers

@rizkit - I found the fix and it's simple. Just run npm i -d postcss and the problem is solved.

Basically, you need both gulp-postcss and postcss plugins in your dependencies for this to work correctly. I'm assuming the gulp-postcss plugin will need to update the postcss package reference in the project to fix it properly, so we only need to include gulp-postcss in the future.

like image 134
Billy Avatar answered Sep 16 '22 14:09

Billy