57

I'm getting the following when I run "gulp". Looks like I have a mixed of CLI and Local version, not really sure how to solve this problem.

cabox@box-codeanywhere:~/workspace/apps/web-ui$ gulp -v
[22:44:23] CLI version 2.0.1
[22:44:23] Local version 4.0.0
cabox@box-codeanywhere:~/workspace/apps/web-ui$
cabox@box-codeanywhere:~/workspace/apps/web-ui$
cabox@box-codeanywhere:~/workspace/apps/web-ui$ gulp
[22:44:28] Using gulpfile ~/workspace/apps/web-ui/gulpfile.js
[22:44:28] Starting 'default'...
[22:44:28] 'default' errored after 5.41 ms
[22:44:28] TypeError: gulp.hasTask is not a function
    at /home/cabox/workspace/apps/web-ui/node_modules/run-sequence/index.js:23:22
    at Array.forEach (<anonymous>)
    at verifyTaskSets (/home/cabox/workspace/apps/web-ui/node_modules/run-sequence/index.js:17:11)
    at runSequence (/home/cabox/workspace/apps/web-ui/node_modules/run-sequence/index.js:130:2)
    at /home/cabox/workspace/apps/web-ui/gulpfile.js:187:5
    at taskWrapper (/home/cabox/workspace/apps/web-ui/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at asyncRunner (/home/cabox/workspace/apps/web-ui/node_modules/async-done/index.js:55:18)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
cabox@box-codeanywhere:~/workspace/apps/web-ui$ ^C
user1187968
  • 7,154
  • 16
  • 81
  • 152

6 Answers6

75

Gulp v4 has breaking changes and that creates some problems with run-sequence package.

As I do not have your gulpfile.js, all I can say upto this point is to try to use Gulp4's gulp.series and gulp.parallel with your gulp tasks, instead of run-sequence.

you may receive an error of the sort of like 'task1, 'task2' could not be completed', in the function of the task, accept the done callback and call the callback in your tasks at the end of the function

Example:

gulp.task('task1', gulp.series('task1-1', function (done) {
   // task 1 code here
    done();
}));

gulp.task('task2', gulp.series('task2-1', function (done) {
   // task 2 code here
    done();
}));

// Similarly Tasks 3 and 4 Code here

gulp.task('main', gulp.series('task1', 'task2', 'task3', 'task4', function (done) {
    done();
}));
Saurabh Pati
  • 795
  • 6
  • 14
33

Saurabh Pati's answer is the answer. BTW a quick workaround would be to replace run-sqeuence package with the gulp4-run-sequence package.

If your project has Gulp installed locally, remove local version of Gulp:

yarn remove gulp

Then open the package.json and replace "run-sequence": "^0.3.6", with

"gulp4-run-sequence": "^1.0.0",

Now run

yarn install

In your Gulpfile.js, replace runSequence = require('run-sequence'), with

runSequence = require('gulp4-run-sequence'),

And, you are done. :)

Mayeenul Islam
  • 4,532
  • 5
  • 49
  • 102
28

All that matters is the Local Version. Since gulp 4.0.0 introduced breaking changes, you can simply do what I did --- explicitly set the local package back to a working version:

npm install --save-dev gulp@3.9.1

This has bit me a couple times recently and I'll be coming back here again, I'm sure.

Note: The dependencies of gulp 3.9.1 have many security vulnerabilities. You should not do this.

Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
dvdrtrgn
  • 1,139
  • 10
  • 21
0

I got the same problem and couldn't install gulp 3.9.1 version. After instaling, was any way 4.0.0. Installing the same version for -g and --save dev - solves the issues with hasTask and gives 3.9.1 version for CLI and local. Don't fix the vulnerabilities. It turns gulp local to 4.0.0. So just install npm i gulp @3.9.1 -g and npm i gulp @3.9.1 --save-dev

0

I had this same error..From my research i discovered is due to gulp version 4.0. Therefore if you have gulp4.0 and above this solution is for you..Install a later version like npm install --save-dev gulp@3.9.1, then i deleted my node_modules folder and ran npm install again from the command prompt..and everything works perfect now..thanks to @tptompkins.

  • Please post a link where it states that the function is deprectated or not working anymore in gulp 4.0 - in order to inform the poster accordingly. – santamanno Oct 12 '19 at 12:05
-1

After reading all the suggestions here, what worked for me was running 'npm install --save-dev gulp@3.9.1'. I didnt have to delete my node_modules folder or having to specify '-g' or '--save-dev'.

Dharman
  • 30,962
  • 25
  • 85
  • 135