gruntjs / grunt-contrib-requirejs

Optimize RequireJS projects using r.js.
http://gruntjs.com/
MIT License
504 stars 105 forks source link

Only after compile: "underscore" has not been loaded yet for context. #60

Closed kyrstenkelly closed 10 years ago

kyrstenkelly commented 10 years ago

Here is my requirejs task:

  requirejs: {
    compile: {
        options: {
          mainConfigFile: 'app/main.js',
          name: 'main',
          include: compileList, // A list of our widgets pulled in from other repos
                                                // through bower
          paths: {
            'jquery': 'bower_components/jquery/jquery',
            'jquery-ui': 'bower_components/jquery-ui-amd/jquery-ui-1.10.0/ui/minified/jquery-ui.min',
            'bootstrap': 'bower_components/bootstrap/docs/assets/js/bootstrap.min',
            'underscore': 'bower_components/underscore/underscore'
          },
          shim: {
            'jquery-ui': {deps: ['jquery']},
            'bootstrap': {deps: ['jquery', 'jquery-ui']},
            'backbone':  {
              deps: ['jquery', 'underscore'],
              exports: 'Backbone'
            }
          },
          exclude: ['jquery', 'jquery-ui', 'bootstrap'],
          insertRequire: ['main'],
          out: 'dist/<%= pkg.name %>.js'
       }
      }
    }

When I try to load my page I keep getting the error Module name "underscore" has not been loaded yet for context: _. Use require([]) but this doesn't happen when I run the un-compiled version of our app.

I had to exclude jquery, jquery-ui and bootstrap because those were throwing other errors (it kept telling me jQuery is not defined).

I'm sure I'm just not setting some option correctly. I've been fiddling with the shim, insertRequire and keepAmdefine but I can't get the underscore error to resolve.

kyrstenkelly commented 10 years ago

While I'm still having some other issues, I got this one resolved.