gulp-grunt icon indicating copy to clipboard operation
gulp-grunt copied to clipboard

Spawn errors ENOENT when using options.base to specify custom Gruntfile.js location

Open ellywebdev opened this issue 8 years ago • 4 comments

Hi there,

As a few have pointed out already, in your documentation it says that setting options.base will be used for specifying a custom Gruntfile.js location. However, in the code it is being used as the path to the grunt executable. This is causing ENOENT errors because it is trying to spawn from an invalid location. (Since the grunt executable would not likely exist in the same directory as the Gruntfile, its either globally installed /usr/bin (etc) and on the PATH, or when grunt-cli is a dependency it would be in node_modules/.bin)

A solution would be to have two separate options for the Gruntfile location and the grunt executable

As a side note, the mocha tests are not picking this error up because it seems that the overriding of process.stdout.write is having the side effect of squelching the failing tests.

ellywebdev avatar Oct 22 '16 17:10 ellywebdev

+1

jmcmullen avatar Nov 17 '16 06:11 jmcmullen

+1, for me too..

dmitryshepelev avatar Nov 23 '16 11:11 dmitryshepelev

Don't have a fix for this, but I do have a workaround. There is a grunt plugin called grunt-hub, whose purpose is to load and run tasks in grunt files that are in child folders/projects. I was able to leverage this plugin to get around this error.

first, setup gulp-grunt in your gulpfile with no "base" option (you can specify other options if you want) ...

require('gulp-grunt')(gulp); 

This will look for a gruntfile in the same folder with your gulpfile. So, we create a gruntfile there that uses grunt-hub, and configure it to look for the child gruntfile that you need to run, and register tasks to run specific hub targets.

module.exports = function(grunt) {
    grunt.loadNpmTasks('grunt-hub');

    grunt.initConfig({
        hub: {
            testCode: {
                src: ['path/to/child/Gruntfile.js'],
                tasks: ['jshint', 'nodeunit']
            },
            build: {
                src: ['path/to/child/Gruntfile.js'],
                tasks: ['sass','minify','uglifyjs']
            }
        }
    });

   grunt.registerTask('test',['hub:testCode']);
   grunt.registerTask('build',['hub:build']);
   grunt.registerTask('all',['hub:testCode','hub:build']);
}

Finally, back in your gulp file, use gulp-grunt like normal to use the tasks you created in your new gruntfile (which will in turn use hub to run the grunt tasks in the file further down in the directory tree).

gulp.registerTask('do-grunt-things', ['grunt-test']);
gulp.registerTask('combine', ['some-gulp-task', 'grunt-build', 'some-other-gulp-task']);

It's not optimal, but it works. Hope this helps. It worked for me.

Bradleycorn avatar Jan 02 '17 21:01 Bradleycorn

+1

wesleypimentel avatar Jun 06 '17 02:06 wesleypimentel