{"record":{"id":"c5017f139ba8eeba","repo":"OrchardCMS/OrchardCore","slug":"jquery-requires-a-window-with-a-document","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.4.1/jquery.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.4.1/jquery.js#L13-L49","documentation":"When jQuery is loaded in a CommonJS/Node-like environment without a global document, module.exports is a factory function that requires a window argument; if that window lacks a document, jQuery throws this Error instead of initializing. It prevents jQuery from running in environments with no DOM.","triggerScenarios":"Requiring/importing jquery.js in Node.js, a web worker, SSR, or a headless context without passing a window object that has a document, e.g. require('jquery') without jsdom, or calling the returned factory with `{}`.","commonSituations":"Server-side rendering scripts importing jQuery; unit tests in Node without jsdom; script execution order where jQuery loads before a DOM exists; accidental CommonJS interpretation of the script in a bundler.","solutions":["Ensure jQuery runs in a browser environment where window.document exists","In Node tests, initialize a jsdom window first: const { JSDOM } = require('jsdom'); const { window } = new JSDOM(''); const $ = require('jquery')(window);","Exclude jquery from SSR bundles or import it only inside client-only code (e.g. useEffect / onMounted)","If loading via bundler config, mark jquery as external or browser-only"],"exampleFix":"// before (Node SSR)\nimport $ from 'jquery';\n// after\nimport { JSDOM } from 'jsdom';\nconst { window } = new JSDOM('<html></html>');\nconst $ = require('jquery')(window);","handlingStrategy":"type-guard","validationCode":"if (typeof document === 'undefined') { throw new Error('jQuery requires a browser DOM environment'); }","typeGuard":"function hasDocument(w) { return !!w && typeof w.document !== 'undefined' && w.document !== null; }","tryCatchPattern":"try { const $ = require('jquery')(someWindow); } catch (e) { if (e.message.includes('window with a document')) { // provide jsdom window or skip client-only path } }","preventionTips":["Import jQuery only in browser/client bundles","Use jsdom in Node tests before requiring jQuery","Exclude vendor DOM libs from SSR entry points","Load jQuery via plain <script> when no bundler is involved"],"tags":["javascript","jquery","node","ssr","dom"],"backgroundTag":"missing-dependency","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}