question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using jQuery plugins with browserify: jQuery is not defined

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
domeniccommented, Sep 3, 2014

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

1reaction
bcgoodmatecommented, Oct 27, 2020

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

This one still works!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

order dependencies: jQuery is not defined with browserify
I am trying to use a plugin that is ...
Read more >
Javascript – order dependencies: jQuery is not defined with browserify
I am trying to use a plugin that is in /js/lib/stellar.jquery.js : var $ = require('jquery'); require('./lib/stellar.jquery') $(function(){ $.stellar(); });.
Read more >
5 Easy Ways to Fix the "jQuery is Not Defined" Error - Kinsta
The "jQuery is not defined" error means a call for a specific jQuery that wasn't available when the website loaded. Here's how to...
Read more >
Browserify support for JsRender and JsViews
Note: In fact if jQuery is not defined globally, require('jsrender') ... as a plugin (attached to that jQuery instance) – and returns the...
Read more >
jquery - npm
For jQuery to work in Node, a window with a document is required. Since no such window exists natively in Node, one can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found