window is not defined at _.extend.start in Backbone App

Lord I spent an inexcusable amount of time tracking down this error. Maybe because I’m daft as the wall I’m sitting next to, this solution should be obvious, therefore no one has written a coherent resolution to it. You’d think that this would be front and center in the Browserify examples but alas, it’s nowhere to be found. At any rate, I hope this will help someone spend a little less time on it.

If you are building a Backbone app using Browserify for managing dependencies you may come across the “window is not defined at _.extend.start” error early on in your development. This error literally explains nothing and the stack trace does little to help you out either. The problem, it turns out, is your configuration of jQuery and Backbone within Browserify.

For your require statements you need to structure your jQuery and Backbone definitions something like this:

var $ = require(‘jquery’)(window);
var Backbone = require(‘backbone’);
Backbone.$ = $;

Within Browserify, jQuery requires the window object to be defined explicitly AND Backbone then requires that instantiation to be attached to it.

If this helped you out and saved you a day of research, please consider donating from the menu above.


PS: If you are using jquery 2.1.0 or greater than (window) is not required.

One thought on “window is not defined at _.extend.start in Backbone App

Leave a Reply

Your email address will not be published. Required fields are marked *