2

I have errors loading jquery-menu-aim and bootstrap with Require.js in backbone project.

Here are what I had defined in main.js of :

requirejs.config({
    enforceDefine: true,
    paths: {
      //declare path jquery, backbone, underscore,and other library here....
      "jquery-menu-aim" : "libs/jquery/jquery.menu-aim",
      "bootstrap" : "libs/jquery/bootstrap.min"
    },
    shim: {
      "jquery-menu-aim" : {
        deps: ["jquery"] ,
        exports: "Jquerymenuaim"
       },
       "bootstrap" : {
        deps: ["jquery"] ,
        exports: "Bootstrap"
      }
   }
});

Errors : Uncaught Error: No define call for jquery-menu-aim http://requirejs.org/docs/errors.html#nodefine require.js:8 Uncaught Error: No define call for bootstrap http://requirejs.org/docs/errors.html#nodefine

When I defined it in my view. I think maybe I was wrong in defining library in Shim config, but I can not found it in google.

Any help would be appreciated. Thanks.

1 Answer 1

4

Your shim for Bootstrap is definitely wrong because Bootstrap does not define a symbol named Bootstrap. Here's what I use:

bootstrap: {
  deps: ["jquery"],
  exports: "jQuery.fn.popover"
},

The jQuery.fn.popover method is something that Bootstrap defines. If it is absent after RequireJS has loaded Bootstrap, that's a sure sign that Bootstrap has not loaded.

Your shim for jquery.menu-aim is similarly wrong. Looking at the code, I see it is a jQuery plugin. You should change your shim to check for a function it adds to jQuery. jQuery.fn.menuAim looks like a good candidate.

Sign up to request clarification or add additional context in comments.

2 Comments

Works great, thanks Louis. But how could you know bootstrap exports is jQuery.fn.popover?
I've read Bootstrap's code. Another way to go about it would be to just read the doc and pick a method that the plugin you are using (Bootstrap acts as a plugin) makes available. So if the doc says that the plugin makes a new method named jQuery.foo available, you want to check for jQuery.fn.foo. The .fn is necessary because that's where methods available on jQuery objects are stored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.