在gulp 4.0

时间:2015-11-05 21:36:14

标签: javascript node.js gulp

我试图在将文件发送到browserify之前操作文本,我试图使用gulp.series来执行此操作。以下是:

gulp.task('dev_urls', function() {
  gulp.src([ 'app/index.js' ])
      .pipe(...)
      .pipe(gulp.dest(...))

gulp.task('build_dev',
  gulp.series('dev_urls', 'browserify', gulp.parallel('copy')))

当我从命令行使用build_dev执行gulp build_dev任务时,我收到此错误:

/usr/local/lib/node_modules/gulp/bin/gulp.js:121
    gulpInst.start.apply(gulpInst, toRun);
                  ^

TypeError: Cannot read property 'apply' of undefined
  at /usr/local/lib/node_modules/gulp/bin/gulp.js:121:19
  at doNTCallback0 (node.js:407:9)
  at process._tickDomainCallback (node.js:377:13)
  at Function.Module.runMain (module.js:477:11)
  at startup (node.js:117:18)
  at node.js:951:3

我怎样才能让它发挥作用?

编辑: 我在这个文件中遇到同样的错误:

var gulp = require('gulp');
gulp.task('build_dev', function() {
  console.log(1);
})

1 个答案:

答案 0 :(得分:1)

您需要从函数返回。

gulp.task('dev_urls', function() {
    return gulp.src([ 'app/index.js' ])
        .pipe()
}

还要确保正确安装gulp。

$ sudo rm /usr/local/bin/gulp
$ sudo rm -rf /usr/local/lib/node_modules/gulp
$ npm uninstall gulp

$ npm install gulpjs/gulp-cli#4.0 -g

# install Gulp 4 into your project
$ npm install gulpjs/gulp.git#4.0 --save-dev