当我尝试使用多个gulp插件时,我收到错误TypeError: "plugin-name" is not a function
。
我正在使用Gulp 4
我的gulp文件
var gulp = require('gulp');
var posthtml = require('gulp-posthtml');
gulp.task('posthtml', function () {
var plugins = [
require('posthtml-doctype')({doctype: 'HTML 5'}),
('posthtml-alt-always')()
];
var options = { closingSingleTag: 'slash' };
return gulp.src('*.html')
.pipe(posthtml(plugins, options))
.pipe(gulp.dest('./dest'));
});
错误
[08:35:15] TypeError: "posthtml-alt-always" is not a function
at /Users/jitendra/my-projects/posthtml/gulpfile.js:8:39
at taskWrapper (/Users/jitendra/my-projects/posthtml/node_modules/undertaker/lib/set-task.js:13:15)
at bound (domain.js:287:14)
at runBound (domain.js:300:12)
at asyncRunner (/Users/jitendra/my-projects/posthtml/node_modules/async-done/index.js:36:18)
at nextTickCallbackWith0Args (node.js:452:9)
at process._tickCallback (node.js:381:13)
at Function.Module.runMain (module.js:449:11)
at startup (node.js:139:18)
at node.js:999:3
答案 0 :(得分:3)
这种语法有什么用?
require('posthtml-doctype')({doctype: 'HTML 5'}),
('posthtml-alt-always')()
尝试将前置需求添加到第二个:
require('posthtml-doctype')({doctype: 'HTML 5'}),
require('posthtml-alt-always')()