Using jquery with a browser

I am trying to use jQuery with a browser with the jquery-browsify module. I need a module in my client.js script as such:

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

and when I start my node server, after I start the browser, I get the error "window is not defined". What am I doing wrong?

+5
source share
3 answers

Browserify can handle CommonJS modules, as well as AMD modules with conversion deamdify, so you no longer need to use a padding.

To be clear, I only noticed AMD support in jQuery 2.0.0

+3
source

jQuery is now compatible with CommonJS starting from version 2.1.0

+3
source

jquery JS-, module.exports = $.

browserify-shim.

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

Alternatively, you can also use jquery-browserify , but then you are tied to the jquery version that this module made compatible with JJ.

+2
source

All Articles