grunt-contrib-requirejs task stops Grunt without errors

2k Views Asked by At

I have a problem where my grunt-contrib-requirejs task stops my grunt processes. It does this with no errors at all. I need help identifying the issue.

My overall task

grunt.registerTask('build', [
    'clean:dist',
    'jshint',
    'handlebars',
    'requirejs',
    'concat:dist',
    'uglify',
    'compass',
    'imagemin',
    'cssmin',
    'copy'
]);

This is my task configuration

requirejs: {
    dist: {
        options: {
            baseUrl: 'app',
            optimize: 'none',
            optimizeCss: 'none', // We use cssmin for this
            preserveLicenseComments: true,
            dir: 'dist/',

            useStrict: true,
            wrap: false,
            findNestedDependencies: true,

            //If set to true, any files that were combined into a build bundle will be
            //removed from the output folder.
            removeCombined: true,

            paths: {
                aura: '<%= settings.bower %>/aura/lib/aura',
                underscore: '<%= settings.bower %>/underscore/underscore',
                eventemitter: '<%= settings.bower %>/eventemitter2/lib/eventemitter2',
                backbone: '<%= settings.bower %>/backbone/backbone',
                handlebars: '<%= settings.bower %>/handlebars/handlebars',
                text: '<%= settings.bower %>/requirejs-text/text',
                jquery: '<%= settings.bower %>/jquery/jquery'
            },

            shim: {
                backbone: {
                    exports: 'Backbone',
                    deps: ['underscore', 'jquery']
                },
                underscore: {
                    exports: '_'
                },
                handlebars: {
                    exports: 'Handlebars'
                }
            },

            modules: [{
                name: "app",
                include: ["aura","jquery"]
            }],

            onBuildWrite: function( name, path, contents ) {
                grunt.log.writeln( 'Writing: ' + name );
                return contents
            },

            done: function(done, output) {
                var duplicates = require('rjs-build-analysis').duplicates(output);

                if (duplicates.length > 0) {
                    grunt.log.subhead('Duplicates found in requirejs build:');
                    grunt.log.warn(duplicates);
                    done(new Error('r.js built duplicate modules, please check the excludes option.'));
                }

                grunt.log.writeln('All done');

                done();
            }

        }
    }
}

I tried running it with the -v flag, but I get no errors or warnings. It then just stops, and does not run the other tasks that I defined, I don't get the custom loggings that I defined. I get this output:

Running "requirejs" task

Running "requirejs:dist" (requirejs) task
Verifying property requirejs.dist exists in config...OK
File: [no files]
Options: logLevel=0, done=undefined, baseUrl="app", optimize="none", optimizeCss="none", preserveLicenseComments, dir="dist/", useStrict, wrap=false, findNestedDependencies, removeCombined, paths={"aura":"bower_components/aura/lib/aura","underscore":
"bower_components/underscore/underscore","eventemitter":"bower_components/eventemitter2/lib/eventemitter2","backbone":"bower_components/backbone/backbone","handlebars":"bower_components/handlebars/handlebars","text":"bower_components/requirejs-text/t
ext","jquery":"bower_components/jquery/jquery"}, shim={"backbone":{"exports":"Backbone","deps":["underscore","jquery"]},"underscore":{"exports":"_"},"handlebars":{"exports":"Handlebars"}}, modules=[{"name":"app","include":["aura","jquery"]}], onBuild
Write=undefined
>> Tracing dependencies for: app

It seems from this output that the done function is not defined, but I did define it, I even used a example from the grunt-contrib-requirejs readme.

I'm using [email protected] and [email protected] with [email protected]. Node is version v0.8.16

Update one

I tried upgrading my Node, I'm now on v0.10.17 but no changes here.

I removed aura from my modules include, it now looks like this:

modules: [{
    name: "app",
    include: ["jquery"]
}],

This gave me a little more input, but it still stops my Grunt, and does not run my done function, I get this output:

>> app.js
>> ----------------
>> bower_components/aura/lib/platform.js
>> bower_components/aura/lib/base.js
>> bower_components/aura/lib/logger.js
>> bower_components/aura/lib/aura.extensions.js
>> bower_components/aura/lib/aura.js
>> app.js
3

There are 3 best solutions below

0
On BEST ANSWER

The issue is that your done function is failing and the grunt task wasn't set up to forward the error to you. I made a PR that you can look at here to resolve the issue.

0
On

I found my problem as a issue on GitHub here: https://github.com/gruntjs/grunt-contrib-requirejs/issues/37

But there is no solution yet, I might have to look in to the error myself.

1
On

If you remove the entire "done" section from the requireJS options, it won't halt the task list execution, however you will loose the ability to perform analysis on your compiled code