Joseph Ledesma Gabito
Joseph Ledesma Gabito

Reputation: 361

requirejs optimizer failed to load in jquery

I'm optimizing my requirejs app along with backbone and jquerymobile, the following is my file structure:

/application
    /app
       /models
       /views
       /collections
    /scripts
       main.js
       text.js
       /assets
            backbone.js
       /libs
            /jquery
                /jquery.js
                /jquery-mobile.js
 app.js
 r.js
/public
    /css
        /style.css

In the console, I tried to run to ff command:

node ../r.js -o name=main out=../build.js baseUrl=. paths.models=../app/models paths.app=../app

I made sure that paths are well defined and properly working except with this error( this is what I am getting when running the command):

Tracing dependencies for: main
Error: Module loading did not complete for: jquery
    at Function.traceDependencies (/home/dunhak/public_html/my_path/etc/application/r.js:15117:19)

Thank you so much!

Upvotes: 4

Views: 2597

Answers (1)

shovemedia
shovemedia

Reputation: 191

Some of this will depend on the order you load your scripts. Is jQuery loaded before require.js or the other way around?

The last few lines of jQuery may hold the clue to a solution:

if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
    define( "jquery", [], function () { return jQuery; } );
}

My guess is that you're doing something like:

var $ = require('jquery'); //lower-case Q

personally, I've been doing:

var $ = require('jQuery'); //upper-case Q

this all may depend on your require.config -- I use something like:

require.config({
    baseUrl: "/js",

    paths : {
        jQuery: 'lib/jquery-1.7.1.min'
        //, etc...
    }
})

Another thing to think about: You may not want jQuery included as part of your optimized output -- instead, load the pre-minified version from a CDN (etc). In that case, you need to exclude the jquery module as described here: http://requirejs.org/docs/jquery.html

modules: [
    {
        name: "main",
        exclude: ["jquery"]
    }
]

Upvotes: 4

Related Questions