Jorg
Jorg

Reputation: 7250

RequireJS, Shim, dependencies not properly loading

I've been working on a project that has more front end scripting than I'm used to, and I decided to use RequireJS to keep it organized. After mucking around all night, I'm still having some issues where certain dependencies seem to load after the fact.

For instance, Sammy needs jQuery to work. Refreshing my app results in a 'Sammy, function undefined' sort of error. Is the Require function executing before jQuery is loaded?

Require config:

    require.config({
        paths: {
            'jquery': 'vendor/jquery.2.min',
            'sammy': 'vendor/sammy',
        },
        shim: {
            'jquery': {
                debs: [],
                exports: '$'
            },
            'sammy': {
                debs: ['jquery'],
                exports: 'Sammy'
            }
            ...

As for my navigation:

define([
    'jquery',
    'sammy'
], function($, Sammy) {

    return Sammy(function() {
    ...

In about 10 percent of my tests, upon hitting the Sammy function, the app poops out with the following:

Uncaught ReferenceError: jQuery is not defined sammy.js:2120
Uncaught TypeError: undefined is not a function 

The RequireJS way of working mystifies me. What am I missing?

Upvotes: 2

Views: 4543

Answers (1)

jgillich
jgillich

Reputation: 76369

You have a typo in your configuration, the correct property name would be deps instead of debs as specified in the documentation.

'jquery': {
    deps: [],
    exports: '$'
},
'sammy': {
    deps: ['jquery'],
    exports: 'Sammy'
}

Upvotes: 10

Related Questions