Gulp JS 任务输出 NodeError: Callback called multiple times

编程入门 行业动态 更新时间:2024-10-04 05:28:46

Gulp <a href=https://www.elefans.com/category/jswz/34/1771451.html style=JS 任务输出 NodeError: Callback called multiple times"/>

Gulp JS 任务输出 NodeError: Callback called multiple times

Gulp JS 任务输出 NodeError: Callback called multiple times

我有五个 Gulp JS 任务,其中一个名为

js_bundle
的任务给我一个错误。报错如下:

NodeError: 多次调用回调函数

这是我的

gulpfile.js

const { src, dest, parallel , series , watch } = require('gulp');
// Gulp Sass
const sass = require('gulp-sass')(require('sass'));
const fileinclude = require('gulp-file-include');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const minify = require('gulp-minifier');
const strip = require('gulp-strip-comments');
const rtlcss = require('gulp-rtlcss');
const rename = require('gulp-rename');

// sasspiler = require('node-sass'); // no-need for gulp-sass v5+

var node_path = '../../../';


function html(cb) {
  src('html/src/**')
  .pipe(dest('html/dist/'));

  cb();
}

function scss(cb) {
  src(['scss/*.scss'])
  // .pipe(sourcemaps.init())               // If you want generate source map.
  .pipe(sass().on('error', sass.logError))  // uses {outputStyle: 'compressed'} in saas() for minify css
  // .pipe(sourcemaps.write('./'))          // If you want generate source map.
  .pipe(dest('assets/dist/css'));

  src(['scss/*.scss', '!scss/style-email.scss'])
  // .pipe(sourcemaps.init())               // If you want generate source map.
  .pipe(sass().on('error', sass.logError))  // uses {outputStyle: 'compressed'} in saas() for minify css
  // .pipe(sourcemaps.write('./'))          // If you want generate source map.
  .pipe(rtlcss())
  .pipe(rename({ suffix: '.rtl' }))
  .pipe(dest('assets/dist/css'));

  // EDITORS
  src(['scss/editors/*.scss'])
  // .pipe(sourcemaps.init())                                           // If you want generate source map.
  .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))   // remove {outputStyle: 'compressed'} from saas() if do not want to minify css
  // .pipe(sourcemaps.write('./'))                                      // If you want generate source map.
  .pipe(dest('assets/dist/css/editors'));

  src(['scss/editors/*.scss'])
  // .pipe(sourcemaps.init())                                           // If you want generate source map.
  .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))   // remove {outputStyle: 'compressed'} from saas() if do not want to minify css
  // .pipe(sourcemaps.write('./'))                                      // If you want generate source map.
  .pipe(rtlcss())
  .pipe(rename({ suffix: '.rtl' }))
  .pipe(dest('assets/dist/css/editors'));

  src(['scss/libs/*.scss'])
  // .pipe(sourcemaps.init())                                           // If you want generate source map.
  .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))   // remove {outputStyle: 'compressed'} from saas() if do not want to minify css
  // .pipe(sourcemaps.write('./'))                                      // If you want generate source map.
  .pipe(dest('assets/dist/css/libs'));

  // SKINS
  src(['scss/skins/*.scss'])
  // .pipe(sourcemaps.init())               // If you want generate source map.
  .pipe(sass().on('error', sass.logError))  // uses {outputStyle: 'compressed'} in saas() for minify css
  // .pipe(sourcemaps.write('./'))          // If you want generate source map.
  .pipe(dest('assets/dist/css/skins'));

  cb();
}

function js_scripts(cb) {
  src(['assets/src/js/*.js','!assets/src/js/bundle.js'])
  // .pipe(uglify())                        // If you minify the code.
  .pipe(dest('assets/dist/js'));

  src(['assets/src/js/charts/*.js'])
  .pipe(uglify())                        // If you minify the code.
  .pipe(dest('assets/dist/js/charts'));

  src(['assets/src/js/apps/*.js'])
  // .pipe(uglify())                        // If you minify the code.
  .pipe(dest('assets/dist/js/apps'));

  cb();
}

/* The task giving me the error */
function js_bundle(cb) {
  src('assets/src/js/bundle.js')
  .pipe(fileinclude({
    prefix: '@@',
    basepath: '@file',
    context: { build: 'dist', nodeRoot: node_path }
  }))
  .pipe(strip())
  .pipe(minify({ minify: true, minifyJS: { sourceMap: false } }))     // Disable, if you dont want to minify bundle file.
  .pipe(dest('assets/dist/js'));

  src(['assets/src/js/libs/**', '!assets/src/js/libs/editors/skins/**'])
  .pipe(fileinclude({
    prefix: '@@',
    basepath: '@file',
    context: { build: 'dist', nodeRoot: node_path }
  }))
  .pipe(strip())
  .pipe(minify({ minify: true, minifyJS: { sourceMap: false } }))     // Disable, if you dont want to minify bundle file.
  .pipe(dest('assets/dist/js/libs'));

  src('assets/src/js/libs/editors/skins/**').pipe(dest('assets/dist/js/libs/editors/skins'));

  cb();
}

function assets(cb){
  src(['assets/src/**', '!assets/src/js/**', '!assets/src/css/**'])
  .pipe(dest('assets/dist/'));

  cb();
}

exports.build = series(html, scss, js_scripts, /* The task giving me the error */ js_bundle, assets);

exports.develop = function() {
    watch(['scss/*.scss','scss/**'], scss)
    watch(['html/src/*.html','html/src/**/*.html'], html)
    watch(['assets/src/**'], assets)
    watch(['assets/src/js/*.js','assets/src/js/charts/*.js', 'assets/src/js/apps/*.js', '!assets/src/js/bundle.js'], js_scripts)
    watch(['assets/src/js/libs/**','assets/src/js/bundle.js'], js_bundle)
};

这里是导致错误的代码片段:

.pipe(fileinclude({
    prefix: '@@',
    basepath: '@file',
    context: { build: 'dist', nodeRoot: node_path }
}))

我试过以下方法:

  • 更新了我怀疑导致错误的
    gulp_file_include
    插件。
  • 控制台记录了前后的函数,检查回调函数是否重复,但无济于事。
  • 删除了
    strip
    minify
    函数,但仍然出现错误,这证实了我对
    gulp_file_include
    插件导致错误的怀疑。
  • 检查了这个 SO 问题如何修复多次调用的回调函数但没有问题作者所说的导致问题的
    gulp-imagemin
    插件

感谢任何帮助,再见

回答如下:

更多推荐

Gulp JS 任务输出 NodeError: Callback called multiple times

本文发布于:2024-05-30 18:20:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770785.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NodeError   JS   Gulp   Callback   times

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!