Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using jQuery plugins with browserify: jQuery is not defined #868

Closed
connor11528 opened this issue Aug 15, 2014 · 6 comments
Closed

using jQuery plugins with browserify: jQuery is not defined #868

connor11528 opened this issue Aug 15, 2014 · 6 comments

Comments

@connor11528
Copy link

I am trying to use browserify with jQuery and a jQuery plugin like so:

var $ = require('jquery');
require('./lib/stellar.jquery')

$(function(){
    $.stellar();
});

I build the final file using gulp (not sure if this matters):

gulp.task('browserify', function(){
    return browserify({
            entries: ['./js/main.js']
        })
        .bundle()
        .on('error', function (err) {
            console.log(err.toString());
            this.emit('end');
        })
        //Pass desired output filename to vinyl-source-stream
        .pipe(source('bundle.js'))
        // Start piping stream to tasks
        .pipe(gulp.dest('./build/'));
});

Anyway when I run in the browser this last line from the stellar.jquery.js file throws a "jQuery is not defined" error:

...
    // Expose the plugin class so it can be modified
    window.Stellar = Plugin;
}(jQuery, this, document));

What's the best way to use jQuery plugins with browserify?

@adamjgrant
Copy link

I think you need Browserify Shim

@domenic
Copy link
Contributor

domenic commented Sep 3, 2014

You should just do global.jQuery = require("jquery").

@imbuks
Copy link

imbuks commented Jan 20, 2015

@domenic You my friend are awesome!

@ankurp
Copy link

ankurp commented May 13, 2015

Was this resolved. Running into same issue even with shim. I have this in my shim

"jquery": "jquery:jQuery"

@giannif
Copy link

giannif commented Jan 8, 2016

jQuery-bridget worked for me, though the plugin I was using is CommonJS compatible, and didn't need to be "shimmed".

import $ from "jquery";
import jQueryBridget from "jquery-bridget"
import Masonry from 'masonry-layout';
// make Masonry a jQuery plugin
$.bridget( 'masonry', Masonry );

@bcgoodmate
Copy link

You should just do global.jQuery = require("jquery").

This one still works!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants