{"record":{"id":"e7c96e340b06d058","repo":"OrchardCMS/OrchardCore","slug":"jquery-requires-a-window-with-a-document-e7c96e","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.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.js#L13-L49","documentation":"jQuery 3.6.0's UMD wrapper throws this when loaded where a 'window' with a 'document' cannot be provided. As in 3.5.1, module loaders get a factory expecting a window argument; calling it without a valid document aborts initialization.","triggerScenarios":"Requiring the 3.6.0 vendored build under Node.js/SSR/tests without jsdom; running it in a worker or sandboxed vm; invoking module.exports(windowLike) with an object missing 'document'.","commonSituations":"After upgrading 3.5.1 → 3.6.0, existing Node-side imports that 'worked' with polyfills fail if the polyfill no longer sets global.document; bundler environment misconfiguration (target: node) pulling the browser file.","solutions":["Ensure a DOM exists before import: use jsdom and require('jquery')(dom.window), or set testEnvironment: 'jsdom' in Jest.","Import the official 'jquery' npm package (3.6.0) rather than the vendored wwwroot copy in non-browser code.","Verify bundler target/env is 'web'/'browser' when shipping jquery.js so it executes only where window exists.","If intentionally headless, do not load jQuery there; use fetch/DOM-free utilities instead."],"exampleFix":"// before\nconst $ = require('./Vendor/jquery-3.6.0/jquery.js'); // throws\n// after\nconst { JSDOM } = require('jsdom');\nconst $ = require('jquery')(new JSDOM('<html></html>').window);","handlingStrategy":"validation","validationCode":"if (typeof window === 'undefined' || !window.document) {\n  const { JSDOM } = require('jsdom');\n  const dom = new JSDOM('');\n  global.window = dom.window; global.document = dom.window.document;\n}\nconst $ = require('jquery');","typeGuard":"function domAvailable() { return typeof window !== 'undefined' && window.document !== null; }","tryCatchPattern":"try { const $ = require('./Vendor/jquery-3.6.0/jquery.js'); } catch (e) { if (e.message.includes('window with a document')) { bootstrapJsdom(); } else { throw e; } }","preventionTips":["After upgrading jQuery versions, re-run SSR/test suites — module resolution lines shift but the DOM requirement does not.","Standardize on the npm jquery package for programmatic imports.","Set jsdom testEnvironment in test runners before library import.","Confirm bundler env/target is browser for this vendor file."],"tags":["jquery","upgrade","module-environment","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"}