PostCSS plugin autoprefixer requires PostCSS 8. Update PostCSS or downgrade this plugin.

这个错误来自官方,是说autoprefixer依赖版本是PostCSS 8,然而版本确实是正确的。

这是gulpfile.js中的配置:

gulp.task('autoprefixer', () => {
  const autoprefixer = require('autoprefixer')
  const sourcemaps = require('gulp-sourcemaps')
  const postcss = require('gulp-postcss')

  return gulp.src('./src/*.css')
    .pipe(sourcemaps.init())
    .pipe(postcss([ autoprefixer() ]))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dest'))
})

这是package.json中的配置:

{
    "dependencies": {
        "autoprefixer": "10.0.0",
        "cssnano": "^4.1.10",
        "gulp": "^4.0.2",
        "gulp-changed": "^4.0.2",
        "gulp-postcss": "^8.0.0",
        "gulp-rename": "^2.0.0",
        "gulp-sass": "^4.1.0"
    }
}

解决办法是将 "autoprefixer": "10.0.0", 改为 "autoprefixer": "9.8.6",修改后:

{
    "dependencies": {
        "autoprefixer": "9.8.6",
        "cssnano": "^4.1.10",
        "gulp": "^4.0.2",
        "gulp-changed": "^4.0.2",
        "gulp-postcss": "^8.0.0",
        "gulp-rename": "^2.0.0",
        "gulp-sass": "^4.1.0"
    }
}

文章版权归 鸽听网 所有,未经许可不得转载,责任编辑:小旭旭。

分享到: