Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14581 closed bug (notabug)

global jquery available when using the npm module

Reported by: mchevett@… Owned by:
Priority: low Milestone: None
Component: build Version: 2.1.0-beta2
Keywords: Cc: timmywil
Blocked by: Blocking:

Description

I'm still seeing a global jQuery.

npm install jquery@2.1.0-beta2
var $ = require('jquery/dist/jquery')(window);
$(function(){
    console.log(!!window.jQuery); // logs true
});

browserify the above and check the console.

Change History (4)

comment:1 Changed 6 years ago by m_gol

Cc: timmywil added
Component: unfiledbuild
Priority: undecidedlow

I think this was intended. A lot of jQuery plugins intend on the jQuery variable being available in the global scope so there's no safe way to avoid that.

Things in the browser land are different from the node one, even if coding via browserify.

The question is: does using browserify require for all of the dependencies, including jQuery plugins, to be converted to be registering as npm modules? If not, I'm opposed to changing the status quo; removing the global that is required is a much bigger problem than registering a global that is not used.

cc @timmywil on that

comment:2 Changed 6 years ago by timmywil

Resolution: notabug
Status: newclosed

This is intended behavior for browser emulators in Node. They will not work correctly without the global. $.noConflict(true) will remove it.

comment:3 Changed 6 years ago by mchevett@…

Can you give an example of a browser emulator where this makes sense? I'd like to understand that use case. Thanks.

comment:4 Changed 6 years ago by timmywil

The ticket for adding the global for CJS is here. We will be adding a build option to remove the global for both AMD and CJS environments.

Is there a use case where the global causes problems in the browser? If so, we can revisit.

Note: See TracTickets for help on using tickets.