using jquery with browserify

I am trying to use jQuery with browserify with the module jquery-browserify. I required the module in my client.js script as such:

    var $ = require('jquery-browserify');

and when I run my node server, after i've ran browserify, i get a "window is not defined" error. What am I doing wrong?

jquery is not commonJS compliant, i.e. it doesn't export itself via module.exports = $.

Therefore you need to shim it via browserify-shim.

It will shim any version of jquery or any other non commonJS library like zepto on the fly. Details on how to set this up are included in the readme.

As an alternative you could also use jquery-browserify, but then you are tied to the jquery version that this module made commonJS compliant.

Browserify can process CommonJS modules as well as AMD modules with the deamdify transform so now there should be no need to use a shim.

To be clear I only noticed AMD support in JQuery 2.0.0