javascript - Gulp `TypeError: "插件名称“不是一个函数`

标签 javascript gulp posthtml

当我尝试使用多个 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

最佳答案

这个语法是怎么回事? require('posthtml-doctype')({doctype: 'HTML 5'}), ('posthtml-alt-always')()

尝试在第二个前面添加 require: require('posthtml-doctype')({doctype: 'HTML 5'}), require('posthtml-alt-always')()

关于javascript - Gulp `TypeError: "插件名称“不是一个函数`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36672273/

相关文章:

javascript - 为什么函数名前需要写 "javascript:"?

javascript - Gulp.js : Reload altered php/html pages

javascript - 在 JavaScript 中根据需要解析 HTML 模板

javascript - Materialise 的 Parallax 导致 Boostrap 的 Modals/Collapse 在 Chrome 上消失

javascript - Selenium /VBA : clicking xpath using Javascript

javascript - 将文件移动到同名文件夹中的 Google Apps 脚本

具有多个图像的 gulp-image-resize

css - 使用 Gulp 编译 Sass 并缩小 vendor css

javascript - Parceljs/PostHTML - 防止 .htm 文件被重命名为 .html