0

I am using requireJS for the first time. I got it working fine then came to optimize the files to minify and concatenate and now I get the error "Uncaught TypeError: undefined is not a function" the error is on line 8175 of front-built.js. I have left the file unminifed for this question to make it easier to identify the problem.

My main JS file before optimization looks like this (works fine): http://thebeer.co/js/front.js

And after optimization (throws the error on line 8175): http://thebeer.co/js/front-built.js

Hope someone is more familier with requireJS than me and can fix this issue. Is may be the way I'm including my JS file before optimization. I'm really not sure.

1 Answer 1

5

I see the problem there:

define('globals',["jquery"],(function($){
  var   siteWrap = $('#siteWrap'),
        membersTab = $('#membersTab'),
        mID = siteWrap.attr('mID');

  if(window.location.host == "dev.thebeer.co"){
    var staticURL = "http://static.thebeer.co";  
  }else{
    var staticURL = "https://static.meshmesh.us"; 
  }

  // ... SNIP SNIP ....

})());

You're not passing jQuery to the anonymous function, therefore $ is undefined inside the function. That last line should be like this:

})(jQuery));
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure the answer is quite right; the normal approach is to provide a function that takes the module dependencies as parameters: define('globals', ["jquery"], function($) { ... });

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.