Skip to content

Document that Node.js without window needs the jquery/factory or jquery/factory-slim entry points #262

@jakerella

Description

@jakerella

Hi folks! Looks like in v4.0.0 the UMD wrapper changed for CommonJS environments (it was simplified). This breaks any environment where the global object is not a DOM Window. I have a minimal example (below as well as at the link here). When I copy the old UMD wrapper from v3 into the v4 dist file things work as expected.

I'm not sure if the removal of the assignment of a window parameter was intentional, so I have not submitted a PR with the "fix" (as maybe this is intended). Can someone take a look? If this is a bug, I'm happy to submit a PR for the fix -- which, IMO is simply using the UMD wrapper from v3.

MINIMAL TEST CASE:

# Install dependencies
npm i jsdom
npm i jquery3@npm:jquery@3
npm i jquery4@npm:jquery@4
const JSDOM = require('jsdom').JSDOM
const window = (new JSDOM('<html></html>')).window
const jQuery3 = require('jquery3')(window)
const jQuery4 = require('jquery4')(window)  // This will throw an Error: "jQuery requires a window with a document"

In jQuery v3.7.1, the UMD wrapper has the code below for CommonJS environments:

module.exports = global.document ?
	factory( global, true ) :
	function( w ) {
		if ( !w.document ) {
			throw new Error( "jQuery requires a window with a document" );
		}
		return factory( w );
	};

In jQuery v4.0.0, the UMD wrapper has the code below for CommonJS environments:

module.exports = factory( global, true );

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions