question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to find gulp task default when requiring a module that defines default gulp task

See original GitHub issue

I am trying to require a gulpfile (someGulpfile.js) in my own gulpfile (gulpfile.js) from where I run the gulp command. When I try to use the tasks defined in someGulpfile it throws an error on console saying Task 'default' is not in your gulpfile even though I just did require('./someGulpfile'); in my gulpfile.js

I found out that this somewhat works but it does not output every task that is run (for example it does not output, Starting sometask, Finished sometask, Starting default, …) and if there is an error it does not show the error and where it happened but errors out in the gulp library code where it has trouble formatting the error output.

//gulpfile.js
var gulp = require('gulp');
gulp.tasks = require('./someGulpfile').tasks;

//someGulpfile.js
var gulp = require('gulp');
gulp.task('sometask', function() {});
gulp.task('default', ['sometask']);
module.exports = gulp;

I am using version 3.8.11

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
jmmcommented, May 21, 2015

@ankurp It sounds like your package and the other package are using different instances. I ran into a similar situation recently. Maybe there’s a better solution, but what I did was like this:

// gulpfile.js
var gulp = require('gulp');
require('path/to/someGulpfileGuts')(gulp);

// someGulpfile.js
require('./someGulpfileGuts.js')();

//someGulpfileGuts.js
module.exports = function (gulp) {
  gulp = gulp || require('gulp');
  gulp.task('sometask', function() {});
  gulp.task('default', ['sometask']);
};
0reactions
DemenageurSitecommented, May 24, 2018

Hi. This work in my case. I was facing the “gulp task is not in your gulpfile” error message, when using “gulp-require-tasks” passing the gulp Instance solve the problem :

var gulp            = require('gulp');
var requireTasks    = require('gulp-require-tasks');

requireTasks({
    passGulp: true,
    gulp: gulp
}); 

Many thanks for your post !

Read more comments on GitHub >

github_iconTop Results From Across the Web

When I run gulp in my project it gives me this error "can't find ...
If you've previously installed gulp globally, run npm rm --global gulp before following these instructions. Install the gulp command. npm ...
Read more >
gulp-typescript - npm
To invoke, simple run gulp . var gulp = require('gulp');. var ts = require('gulp-typescript');. gulp.task('default', function () {.
Read more >
gulp@1 - gulp v1 task | Microsoft Learn
Run the gulp Node.js streaming task-based build system. ... If this input isn't specified, the default task will run. targets - Gulp Task(s)...
Read more >
How to Migrate to Gulp.js 4.0 - SitePoint
Set exports.default to define a default task run when gulp is executed from the command line without a specific task. Gulp Goodness.
Read more >
Gulp Wiki | Barbarian Meets Coding
gulp.task lets you define arbitrary tasks for gulp to perform. ... By default everything before the glob starts but you can redefine it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found