Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using require-js and grunt.js - error missing either a "name", "include" or"modules" option

My Gruntfile.js file:

module.exports = function (grunt) {
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
        requirejs : {
            compile: {
                options: {
                    baseUrl: "public_html/js",
                    mainConfigFile: "public_html/js/config.js",
                    out: "public_html/app.min.js"
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-requirejs');

    grunt.registerTask('default', ['requirejs']);
};

My config.js file:

'use strict';

require.config({
    deps: ['main'],
    paths: {
        jquery: 'vendor/jquery',
        jquery_tokeninput: 'vendor/jquery.tokeninput',
        underscore: 'vendor/underscore',
        backbone: 'vendor/backbone'
    },
    shim: {
        jquery: [],
        jquery_tokeninput: {
            deps: ['jquery']
        },
        backbone: {
            deps: ['vendor/underscore', 'vendor/jquery', 'vendor/jquery.tokeninput'],
            exports: 'Backbone'
        },
        underscore: {
            exports: '_'
        }
    }
});

require(['views/app'], function(AppView) {
  new AppView;
});

When I run grunt requirejs it errors with:

Running "requirejs:compile" (requirejs) task
[Error: Error: Missing either a "name", "include" or "modules" option at function.build.createConfig (D:\project\node_modules\grunt-contrib-requirejs\node_modules\requirejs\bin\r.js:24829:19)]

First time using gruntjs and requirejs so not sure why I'm getting the error.

like image 735
xylar Avatar asked Jul 26 '13 20:07

xylar


1 Answers

Updated the grunt.js file to use name:

module.exports = function (grunt) {
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
        requirejs : {
            compile: {
                options: {
                    name: "views/app",
                    baseUrl: "public_html/js",
                    mainConfigFile: "public_html/js/config.js",
                    out: "public_html/app.min.js"
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-requirejs');

    grunt.registerTask('default', ['requirejs']);
};

and removed the following from the config.js:

require(['views/app'], function(AppView) {
  new AppView;
});
like image 88
xylar Avatar answered Nov 17 '22 13:11

xylar