{"record":{"id":"95a376ba9fe6b316","repo":"OrchardCMS/OrchardCore","slug":"jquery-requires-a-window-with-a-document-95a376","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.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.5.1/jquery.slim.js#L13-L49","documentation":"Identical to the jquery.js case: the UMD wrapper of the slim build detects a module environment where no 'window' with a 'document' exists and throws. The slim build only omits ajax/effects/animations; it still requires a full DOM to initialize.","triggerScenarios":"Requiring jquery.slim.js under Node.js, in a web worker, or inside a vm/sandbox with no global document; invoking the exported factory with an object whose 'document' property is missing.","commonSituations":"SSR or unit tests importing the vendored slim build from wwwroot; bundlers picking jquery.slim.js in a Node target; switching a page from jquery.js to jquery.slim.js in an environment (worker/extension context) that lacks a DOM.","solutions":["In Node/tests, provide a DOM first: const $ = require('jquery')(new JSDOM('').window) using the official npm package, not the vendored file.","Only load jquery.slim.js in real browser window contexts; for workers use DOM-free alternatives.","If the environment legitimately has no DOM, guard the import (dynamic require inside a browser-only branch) so it never executes server-side.","In Jest/jsdom setups, ensure testEnvironment provides window/document before the module is imported."],"exampleFix":"// before\nconst $ = require('./wwwroot/Vendor/jquery-3.5.1/jquery.slim.js'); // throws in Node\n// after\nif (typeof window !== 'undefined' && window.document) {\n  var $ = require('jquery');\n}","handlingStrategy":"validation","validationCode":"if (typeof window === 'undefined' || !window.document) {\n  throw new Error('jquery.slim.js cannot load: no window.document available');\n}\nvar $ = require('jquery');","typeGuard":"function canLoadJQuery() { return typeof window !== 'undefined' && typeof window.document !== 'undefined'; }","tryCatchPattern":"try { $ = require('./Vendor/jquery-3.5.1/jquery.slim.js'); } catch (e) { if (/window with a document/.test(e.message)) { $ = null; /* headless path */ } else { throw e; } }","preventionTips":["Load the slim build only in browser window contexts, never in workers or Node.","Branch imports on typeof window before requiring DOM libraries.","Use the npm 'jquery' package with jsdom for server-side needs.","Document that slim == full minus ajax/effects, but both still need a DOM."],"tags":["jquery","slim","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"}