{"record":{"id":"293cabecebe214ce","repo":"OrchardCMS/OrchardCore","slug":"jquery-requires-a-window-with-a-document-293cab","errorCode":null,"errorMessage":"jQuery requires a window with a document","messagePattern":"jQuery requires a window with a document","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.6.0/jquery.slim.js","lineNumber":31,"sourceCode":" */\n( function( global, factory ) {\n\n\t\"use strict\";\n\n\tif ( typeof module === \"object\" && typeof module.exports === \"object\" ) {\n\n\t\t// For CommonJS and CommonJS-like environments where a proper `window`\n\t\t// is present, execute the factory and get jQuery.\n\t\t// For environments that do not have a `window` with a `document`\n\t\t// (such as Node.js), expose a factory as module.exports.\n\t\t// This accentuates the need for the creation of a real `window`.\n\t\t// e.g. var jQuery = require(\"jquery\")(window);\n\t\t// See ticket #14549 for more info.\n\t\tmodule.exports = global.document ?\n\t\t\tfactory( global, true ) :\n\t\t\tfunction( w ) {\n\t\t\t\tif ( !w.document ) {\n\t\t\t\t\tthrow new Error( \"jQuery requires a window with a document\" );\n\t\t\t\t}\n\t\t\t\treturn factory( w );\n\t\t\t};\n\t} else {\n\t\tfactory( global );\n\t}\n\n// Pass this if window is not defined yet\n} )( typeof window !== \"undefined\" ? window : this, function( window, noGlobal ) {\n\n// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1\n// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode\n// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common\n// enough that all such attempts are guarded in a try block.\n\"use strict\";\n\nvar arr = [];\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.6.0/jquery.slim.js#L13-L49","documentation":"jQuery's UMD/CommonJS wrapper throws this when the library is loaded in a CommonJS environment (module.exports exists) but the supplied window/global object has no document property. jQuery needs a real DOM document at factory time to initialize (e.g. attach events, feature-detect the DOM). jQuery 3.x cannot run in a pure non-DOM environment without a window shim.","triggerScenarios":"Requiring jquery in Node.js without jsdom or any DOM shim: require('jquery') with global.document undefined; passing an object without .document to the factory: require('jquery')(fakeWindow) where fakeWindow.document is missing; loading the browser build (jquery.slim.js) in a worker/SSR/server context.","commonSituations":"Server-side rendering (SSR) of an app that imports jQuery; running jQuery-dependent code in unit tests under Node without jsdom; Web Workers importing jQuery; misconfigured bundlers resolving the wrong build (browser build pulled into a server bundle).","solutions":["In Node/tests, provide a DOM: global document via jsdom — require('jsdom') and pass { window } or set global.window/global.document before requiring jQuery.","Don't import jQuery in server-side code; guard the import or use dynamic import only on the client.","Use a jQuery version/build intended for the environment, or replace the jQuery usage with plain DOM/framework code in non-browser contexts.","If passing a custom window to the factory, ensure it exposes a real document object."],"exampleFix":"// before (Node)\nconst $ = require('jquery'); // throws: no document\n\n// after\nconst { JSDOM } = require('jsdom');\nconst { window } = new JSDOM('<!DOCTYPE html>');\nglobal.window = window;\nglobal.document = window.document;\nconst $ = require('jquery')(window);","handlingStrategy":"validation","validationCode":"// Guard before requiring/using jQuery in Node\nif (typeof document === 'undefined' && typeof global.window === 'undefined') {\n  throw new Error('jQuery requires a DOM environment; use jsdom or skip on the server');\n}\nconst $ = require('jquery')(global.window);","typeGuard":"function hasDom(win) { return !!win && !!win.document && typeof win.document.createElement === 'function'; }","tryCatchPattern":"let $;\ntry { $ = require('jquery')(window); }\ncatch (e) {\n  if (/window with a document/.test(e.message)) {\n    const { JSDOM } = require('jsdom');\n    const dom = new JSDOM('');\n    $ = require('jquery')(dom.window);\n  } else throw e;\n}","preventionTips":["Never import the browser jQuery build in Node, SSR, or Web Worker code paths.","Set up jsdom (global.window/document) in test harnesses before any module requires jQuery.","Isolate jQuery-dependent code behind dynamic import guarded by typeof window !== 'undefined'.","Ensure any custom window object passed to the jQuery factory exposes a real document."],"tags":["jquery","node","dom","environment"],"backgroundTag":"missing-dom-document","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}