5

gulp decided it had enough and it died in my project.

current version

gulp -v
[11:26:35] CLI version 3.9.1
[11:26:35] Local version 4.0.0

if i run one of the tasks that worked yesterday I get the following error:

C:\Program Files\nodejs\node_modules\gulp\bin\gulp.js:129 gulpInst.start.apply(gulpInst, toRun); ^

TypeError: Cannot read property 'apply' of undefined at C:\Program Files\nodejs\node_modules\gulp\bin\gulp.js:129:20 at process._tickCallback (internal/process/next_tick.js:61:11) at Function.Module.runMain (internal/modules/cjs/loader.js:745:11) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

now I have seen this error all over the place and tried many things to fix it

  1. clear node_module and install with rm -rf node_modules and npm i
    • uninstall gulp and gulp-cli from both the global and local packages
    • after which I only installed gulp-cli globally and gulp v4 locally in dev
  2. close everything and restart computer hoping for a magic fix, no luck

EDIT:

also tried the following with no success

  1. delete package-lock.json to force recreate
  2. install gulp globally

what does work

There seems to be some issue where the cli version is not being used properly. If i explicitly use the gulp file from my projects local node_modules folder like this:

node ./node_modules/gulp/bin/gulp.js my-task

then the my-task will run and work correctly

what does NOT work

if i use the following command:

gulp my-task

I get the error quoted at the top of this post.

I am not sure where to go from here, I have a workaround but can not figure out why gulp is dying on me when I am trying to use the latest stable version of both gulp and the cli.

J King
  • 4,108
  • 10
  • 53
  • 103
  • `gulp-cli` is some npm module that lets you run gulp command line commands from Node? I think you need to install gulp globally. You say you only installed gulp-cli globally, which doesn't seem relevant if I'm understanding your problem. try `npm install -g gulp` and doing it again – pushkin Jan 24 '19 at 19:53
  • oh I don't think I misunderstood. looks like gulp comes with gulp-cli (it's a dependency), and that's ultimately what's used when running from command line. Maybe my suggestion won't work though I've seen it work before for this issue – pushkin Jan 24 '19 at 20:02
  • @pushkin adding gulp globally did not solve the issue, thanks – J King Jan 24 '19 at 20:09
  • maybe you've tried everything here, but [here](https://medium.com/gulpjs/gulp-sips-command-line-interface-e53411d4467) – pushkin Jan 24 '19 at 21:46

1 Answers1

3

I just recently upgraded from Gulp 3 to 4, and had a very similar problem (TypeError: Cannot read property 'task' of undefined). Apparently, this was caused by a change in the task method, which (in version 3) would return a reference to the gulp object itself after defining a task, but now (in version 4) returns nothing, thus causing this error when one tries to chain tasks fluently.

The fix for me was to recreate my gulpfile using exports instead.

Since you didn't include your gulpfile in the original question, I don't know if this is your issue or not, but since this question came up while I was looking for some pointers on making the leap from v3 to v4, I thought it might be useful to share.