1
votes

After I optimize an AMD module and it's dependencies using r.js I get this error....

Uncaught TypeError: undefined is not a function

If I load the unoptimized AMD module and have requirejs dynamically load all its dependencies, it works fine.

Here's how I load the module...

require(['jquery', "templates/mainmodule"],
    function ($, mainmodule) {

        var mainModuleObject = new mainmodule();

}

The main module and its dependencies are properly retrieved (I see it using Fiddler), but the main module is undefined when I try to instantiate it. My config mappings are proper, and shims for Underscore and jquery are also fine. Not using Backbone. Have exports for all non-AMD modules. There are no module loading errors appearing in console.

Ideas on how I can troubleshoot this?

1

1 Answers

1
votes

Burned 8 hours solving this incredibly stupid issue.

Require JS Optimizer will create module ID's on the fly for your modules. When you specify "name" and "out" for the module you want to optimize, and the name of the optimized module respectively, "name" should be the module filepath WITHOUT ".js" at the end. "out" SHOULD have ".js" at the end. If you include ".js" to the end of the filepath of the module you are optimizing, it will add that suffix to the module ID, which, for whatever reason, kills the entire execution without ANY sort of error indicating a module ID issue. Holy shit.