TypeError:css.eachInside不是gulp.task中的函数

时间:2018-10-30 16:07:50

标签: javascript css gulp

在控制台中,我得到一个错误,指向postcss-px-to-em,这似乎令人困惑。

[11:59:09] Using gulpfile ~/Sites/ea_re-design/gulpfile.js
[11:59:09] Starting 'css'...
/Users/antonio-pavicevac-ortiz/Sites/ea_re-design/node_modules/postcss-px-to-em/index.js:37
    css.eachInside(function(node) {
        ^

TypeError: css.eachInside is not a function
    at /Users/antonio-pavicevac-ortiz/Sites/ea_re-design/node_modules/postcss-px-to-em/index.js:37:9
    at /Users/antonio-pavicevac-ortiz/Sites/ea_re-design/node_modules/gulp-postcss/index.js:114:32
    at Transform.stream._transform (/Users/antonio-pavicevac-ortiz/Sites/ea_re-design/node_modules/gulp-postcss/index.js:35:5)
    at Transform._read (_stream_transform.js:185:10)
    at Transform._write (_stream_transform.js:173:12)
    at doWrite (_stream_writable.js:388:12)
    at writeOrBuffer (_stream_writable.js:374:5)
    at Transform.Writable.write (_stream_writable.js:291:11)
    at Duplexify.ondata (/Users/antonio-pavicevac-ortiz/Sites/ea_re-design/node_modules/duplexify/node_modules/readable-stream/lib/_stream_readable.js:619:20)
    at emitOne (events.js:125:13)

这是我有问题的gulp文件/任务:

var gif           = require('gulp-if');
var merge         = require('merge-stream');
var sass          = require('gulp-sass');
var prefix        = require('gulp-autoprefixer');
var postcss       = require('gulp-postcss');
var postcssPxToEm = require('postcss-px-to-em');

gulp.task('css', function() {
    var streams = merge();
    var options = {
        base: 12,   // Base font size; 16px by default
    };
    paths.css.forEach(function(path) {
        streams.add(
            gulp
                .src(path.src + '*.scss')
                .pipe(gif(gutil.env.sourcemaps, sourcemaps.init()))
                .pipe(sass())
                .pipe(prefix({ cascade: true }))
                .pipe(gif(gutil.env.sourcemaps, sourcemaps.write('./')))
                .pipe(postcss(postcssPxToEm(options)))

                .pipe(gulp.dest(path.dest))
        );
    });
    return streams;
});

谢谢!

1 个答案:

答案 0 :(得分:0)

我收到此错误,因为我使用的是旧版本的cssnano。通过移至最新版本,该问题得以解决。