Reputation: 6033
I have installed jQuery (v1.11.1) with npm. (I need 1.x since I want to use it with Angular that does not support 2.x).
I am then trying to import the jQuery object with require via browserify, but it seems like the returned object is not the expected so I can't use it.
var jQuery = require('jquery/dist/jquery')(window);
When trying to use it I get Uncaught TypeError: object is not a function
.
What am I doing wrong? How can I use jQuery with browserify?
Upvotes: 3
Views: 1129
Reputation: 76219
jQuery has main
set to dist/jquery.js
, thus you can simply do this:
var jQuery = require('jquery');
jQuery('body').text('hello world');
Note that jQuery exports its factory only if there is no global document
property. When used with Browserify, there is one, so what gets exported is not the factory function, but the regular jQuery object.
Upvotes: 4