0

The problem description is basically identical to the one answered here but the solution given for that one won't work for me.

I've been running Gulp and XAMPP for over a year on this machine to develop a number of Wordpress sites locally before launch. This problem appeared without apparent warning yesterday and is affecting all my local projects. I didn't update anything that I'm aware of preceding this, although I'm running Windows 10 so it's possible an OS update I wasn't aware of broke things.

The full text of the error in PowerShell:

gulp : The term 'gulp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + gulp go + ~~~~ + CategoryInfo : ObjectNotFound: (gulp:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException`

Interestingly, cmd.exe gives a different error, which I can't understand at all:

AssertionError [ERR_ASSERTION]: Task function must be specified at Gulp.set [as _setTask] (C:\xampp\htdocs\domainname.com\node_modules\undertaker\lib\set-task.js:10:3) at Gulp.task (C:\xampp\htdocs\domainname.com\node_modules\undertaker\lib\task.js:13:8) at Object. (C:\xampp\htdocs\domainname.com\gulpfile.js:37:6) at Module._compile (internal/modules/cjs/loader.js:1158:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) at Module.load (internal/modules/cjs/loader.js:1002:32) at Function.Module._load (internal/modules/cjs/loader.js:901:14) at Module.require (internal/modules/cjs/loader.js:1044:19) at require (internal/modules/cjs/helpers.js:77:18) at execute (C:\Users\username\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:36:18) { generatedMessage: false, code: 'ERR_ASSERTION', actual: false, expected: true, operator: '==' }`

EDIT: I got the above error when Gulp was installed globally. After uninstalling it globally (still installed locally to this project) I get the more expected error:

'gulp' is not recognized as an internal or external command, operable program or batch file.`

/END EDIT

NPM commands are not affected, and I've tried various combinations of uninstalling, reinstalling, and updating gulp, including globally, all to no avail. I have tried updating node.js, also to no effect.

Although I've been using Gulp/NPM/Node for some time, I am not a superuser and my command line skills are rudimentary, so there may be something I've missed in my troubleshooting. All thoughts and possibilities will be gratefully accepted, as I'm in a somewhat desperate position and unable to do almost any development work because of this problem.

Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
  • You'll have to run it from a cmd line not powershell. It looks like you may have recently upgraded gulp to v4, which is different than v3.. [See here for more](https://github.com/gulpjs/undertaker/issues/54#issuecomment-314082908).. Can you look in your package.json to see which version of gulp you are on? – Matt Oestreich Feb 29 '20 at 18:46
  • @Matt Oestreich I was running 3.9.1 when the problem occurred; I updated to 4.0.2 while trying to fix it. I'm diving into your link now, though! Can you clarify what exactly I need to run from cmd line? – jessefivey Feb 29 '20 at 19:37
  • You don't need to run anything differently from the command line. Gulp changed how you write tasks https://stackoverflow.com/a/52585938/10431732 – Matt Oestreich Feb 29 '20 at 19:45
  • @Matt Oestreich Thanks for the links! I now understand the changes between Gulp 3 and Gulp 4 and how I will need to edit my gulpfile(s). However, the errors that I am getting aren't about my tasks, but about the 'gulp' command itself. Unless I install Gulp globally (which I hadn't before today) the command line fails to recognize 'gulp' well before it gets to my task. I'm exploring whether I can change my setup to use global packages but that's more of a sidestep/workaround for the problem than a solution, so if you had ideas about that I'd be grateful! – jessefivey Feb 29 '20 at 20:12
  • You cannot run gulp from powershell... if you're in powershell, run `cmd` first then `gulp`... clearly, your issues does have to do with how you are writing your gulp file... it's clear as day... `AssertionError [ERR_ASSERTION]: Task function must be specified` google that. – Matt Oestreich Feb 29 '20 at 20:17
  • or you can try installing [`gulp-cli`](https://stackoverflow.com/a/52365431/10431732) - it's clear it's not a gulp issue since it works from cmd but not from powershell. powershell is looking for a powershell command called gulp... you may be able to get around this by setting an environmental variable.. – Matt Oestreich Feb 29 '20 at 20:21
  • Actually the difference in errors was down to my sloppy troubleshooting; with Gulp installed globally I get the same "Task function must be specified" error in powershell. Maybe I won't ever know, but I'm still baffled about the original "not recognized" error I got and I'm hoping to find the reason it happened. – jessefivey Feb 29 '20 at 20:41
  • Are you running gulp globally in a directory that has a gulp file?? If not, that error makes sense. The not recognized error happens bc PowerShell is looking for a PowerShell command called gulp, which doesn't exist. Well it didn't exist until you installed gulp-cli which resolves the PowerShell error. – Matt Oestreich Feb 29 '20 at 20:43
  • I am not using a global gulpfile because each site has its own theme directory that needs to be watched and its own domain that needs to be refreshed. I had not been attempting anything global with NPM until today; all my projects are in separate folders with their own package.json and gulpfiles, which had been working perfectly in both powershell and cmd until yesterday. – jessefivey Feb 29 '20 at 21:03
  • Right I get that - what I'm saying is you may be getting the Taks function must be specified because you are running gulp globally but in a directory that does not have a proper gulp file - otherwise, that error gets thrown because you have to update your gulp file to 4.x standards. either way it sounds like you got it fixed. – Matt Oestreich Feb 29 '20 at 21:07

1 Answers1

0

Still no idea why or how this happened but for anyone looking for the same answer, I got my setup back to mostly working order by running npm install gulp -g followed by npm install gulp-cli -g --force. It was necessary to force it for some reason because otherwise it couldn't write to the directory? YMMV. Finally, I uninstalled Gulp locally and then reinstalled it. Absolutely no clue why this step was necessary.

Long story short, local/project-level Gulp stopped working, but global Gulp (installed to AppData/Roaming/etc. in Windows 10) works fine and uses your local gulpfile when run locally as normal. I had to rewrite my gulpfiles to use the new task format, but currently everything is working as expected except Browser Sync, which is on me and matter for a different question.

Big thanks to Matt Oestreich in the comments above, whose help was invaluable in solving this. One correction though, it is possible to run Gulp from PowerShell and this was not part of my problem.