{"record":{"id":"f449a6bbc021f412","repo":"OrchardCMS/OrchardCore","slug":"jquery-requires-a-window-with-a-document-f449a6","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.5.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.5.1/jquery.js#L13-L49","documentation":"jQuery is being loaded in a module (CommonJS) environment where no global 'window' with a 'document' exists. The UMD wrapper detects the missing document and throws this error instead of silently producing a broken jQuery instance. jQuery is inherently browser-DOM-bound; it cannot initialize without a window object.","triggerScenarios":"Requiring/importing jquery.js under Node.js, a headless/vm sandbox, a web worker, or any CommonJS loader where 'global.document' is undefined and the returned factory function is invoked with an object lacking a 'document' property.","commonSituations":"Server-side rendering or unit tests (Jest/Node) importing the browser build directly from wwwroot; running the vendored file inside a worker; forgetting jsdom/window polyfill in test setup; accidentally bundling the IIFE browser file with a CJS bundler.","solutions":["In Node/test environments, set up a DOM before requiring jQuery: use jsdom and pass its window, e.g. require('jquery')(dom.window) (install jsdom first).","Do not import the vendored wwwroot copy server-side; import the official 'jquery' npm package which handles module environments.","If loading in a worker/vm, provide a fake window object with a document stub, or avoid jQuery there and use DOM-free APIs.","In Jest, enable testEnvironment: 'jsdom' (default in jsdom-based setups) so window/document exist before jQuery loads."],"exampleFix":"// before (Node)\nconst $ = require('./wwwroot/Vendor/jquery-3.5.1/jquery.js'); // throws\n// after\nconst { JSDOM } = require('jsdom');\nconst $ = require('jquery')(new JSDOM('').window);","handlingStrategy":"validation","validationCode":"// Before loading jQuery in a module context:\nif (typeof window === 'undefined' || !window.document) {\n  // skip jQuery load, use jsdom, or load a DOM-free fallback\n  const { JSDOM } = require('jsdom');\n  global.window = new JSDOM('').window;\n  global.document = global.window.document;\n}","typeGuard":"function hasDom(win) { return !!win && !!win.document && typeof win.document.createElement === 'function'; }","tryCatchPattern":"try { const $ = require('jquery'); } catch (e) { if (e.message.includes('window with a document')) { initJsdomThenRetry(); } else { throw e; } }","preventionTips":["Never import the vendored wwwroot jQuery build in Node/SSR code; use the npm package.","Enable jsdom testEnvironment in Jest/Vitest before modules are loaded.","Check typeof window !== 'undefined' before any DOM-dependent library import.","Keep bundle targets set to browser for browser-only libraries."],"tags":["jquery","module-environment","dom","umd"],"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"}