Still pulling for dependencies separately when compiled - Underscore not loaded for context? #146

Open
KKlonowski opened this Issue Jun 11, 2013 · 3 comments

3 participants

@KKlonowski

A am relatively new to JamJS, and struggle to make it work properly. I've got a very simple project based on Backbone and RequireJS, where I use JamJS to manage dependencies, namely: Backbone, _, Less, $, modernizr, underscore, bootstrap.

I tend to follow the method used by Backbone Boilerplate.

This is the code I use to get the Jam-compiled requireJS config file, together with my application-specific require config:

in html:

< script data-main="/assets/js/app/config" src="/assets/js/jam/compiled.min.js"> < /script>

'Compiled.min.js' is obviously the 600kb minified file generated by Jam. The '/app/config' file is my Require.js configuration file where I'm planning to include all my project-specific code, not managed by the dependency manager.

Here's app/config.js:

require.config({
baseUrl:'/assets/js/',
deps: ['less','modernizer','bootstrap-jam','app/main'],
paths: {
'homeView': 'app/views/homeView'
// Use the underscore build of Lo-Dash to minimize incompatibilities.
,'lodash': '../jam/lodash/dist/lodash.underscore.min'
},
map: {
},
shim: {
}
});
(the files in deps are the ones I need on every page + my main.js - kind of a router.

The problem is that, in my homeView (which is initialized by main.js), I do this sort of thing:

define(['backbone'], function (Backbone) {
return Backbone.View.extend({
el:$('#homepageWrapper'),
initialize: function () {
this.$('#subTitle').text('This text is generated by homeView - the default Backbone View.');
}
})
});
As you can see I want Backbone to be available in this view. I assume that it's available through the compiled Jam code, however when I look in the Network panel in the Web Inspector, I see that this dependency is pulled in separately- this happens to any resource I try to use, not just Backbone.

I suspect that it might be something to do with the error I get as well, which I haven't been able to figure out. When using the compiled jam config, I get:

Uncaught Error: Module name "underscore" has not been loaded yet for context: _. Use require([])

I'd really appreciate help with this

Thanks.

@isimmons

I'm also getting the error Uncaught Error: Module name "underscore" has not been loaded yet for context: _. Use require([]) after compiling. I'm not even using underscore. I'm just trying to get started here and have only the two defined modules.

define(['backbone', 'app/models/SlideModel'], function(Backbone, Slide) {
    var App = {Models: {}};
    App.Models.Slide = Slide;
    return App;
});

and

define(['backbone', 'jquery'], function(Backbone, $) {
    var Slide = Backbone.Model.extend({});
    return Slide;
});

called from main.js

require(['app/app'], function(App) {
    var app = App;
    console.log(app);
});

and loaded in index like this

<script src="http://localhost:8000/vendor/require.js"></script>
    <script src="http://localhost:8000/app/main.js"></script>

It works uncompiled.

I noticed in the compiled require.js it is using _. in one of the functions but I don't see this in the uncompiled version. Could this have something to do with it?

function(e,t){_.apply(e,P.call(t))}
@KKlonowski

Apparently you need to configure require.js optimizer properly... I've given up for the lack of time, so can't help you further..
good luck

@Troland

Hey,you need to configure the require.config.js in the packageDir where the js package live.then in the config.js file add the path/to/require.config.js the the deps array..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment