{"record":{"id":"354f9d9b44e0d738","repo":"OrchardCMS/OrchardCore","slug":"jquery-requires-a-window-with-a-document-slim","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.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.4.1/jquery.slim.js#L13-L49","documentation":"Same throw as in jquery.js: when the slim bundle runs under CommonJS without a global document, the exported factory requires a window argument whose document exists; otherwise it throws 'jQuery requires a window with a document'. jQuery slim lacks ajax and effects but has the same DOM-environment requirement.","triggerScenarios":"Loading jquery.slim.js in Node, a web worker, or SSR context; calling the module-exported factory with an object lacking .document; bundlers evaluating the file outside a browser.","commonSituations":"Server-rendered pages importing slim jQuery; Node test runners without jsdom; script inlining tools executing the file at build time.","solutions":["Run slim jQuery only in a browser environment with a document","Provide a jsdom window in Node: require('jquery-slim')(window) — or use the full package with require('jquery')(window)","Mark jquery as browser-only in your bundler and avoid importing it during SSR","Load the script with the normal <script> tag so it uses the browser global"],"exampleFix":"// before (worker/SSR)\nconst $ = require('./jquery.slim.js')({});\n// after\nconst { JSDOM } = require('jsdom');\nconst $ = require('./jquery.slim.js')(new JSDOM('').window);","handlingStrategy":"type-guard","validationCode":"if (typeof window === 'undefined' || !window.document) { throw new Error('jquery.slim.js requires a browser window'); }","typeGuard":"function hasDocument(w) { return !!w && typeof w.document !== 'undefined' && w.document !== null; }","tryCatchPattern":"try { const $ = require('./jquery.slim.js')(); } catch (e) { if (e.message.includes('window with a document')) { // run only on client or provide jsdom } }","preventionTips":["Use the slim build only in browser contexts","Initialize jsdom before requiring jQuery in Node","Exclude client-only vendor scripts from SSR/build evaluation","Load via <script> tags when bundlers are not needed"],"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"}