From 10cfc60d6cac2f54dfdf5b1b8c57b3670d4832bb Mon Sep 17 00:00:00 2001 From: Jamie Lentin Date: Wed, 29 Jul 2026 10:04:48 +0000 Subject: [PATCH 1/2] Build: require() dependent modules at load time, not run time The CommonJS loader, for both dataTables.js and variants that import it, will vary behaviour depending on whether a root window is defined or not. If no window is available (read: nodejs), then a factory function is returned. Previously, this factory function would require() the base dataTables.js at run time. However, by then a global window might exist, and the wrapper doesn't get the factory class it's expecting. Instead, require() all dependencies whilst the wrapper itself is being require()d, so they get the same environment. References: https://github.com/DataTables/DataTablesSrc/issues/385 --- build/wrapper.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build/wrapper.js b/build/wrapper.js index 42eaae6e..312ec9dc 100644 --- a/build/wrapper.js +++ b/build/wrapper.js @@ -165,15 +165,19 @@ ${exportProps} function umd(script, deps, exp, filename) { let amdLoad = []; let commonjs = []; + let commonjsrequires = ""; let requiresDT = false; + commonjsmodules = "{" + deps.map((dep) => { + return `'${dep}': require('${dep}')`; + }).join(",") + "}"; for (let dep of deps) { amdLoad.push(`'${dep}'`); if (nameFromDependency(dep) === 'DataTable') { commonjs.push(` if (! root.DataTable) { - require('${dep}')(root); + root.DataTable = cjsModules['${dep}'](root); } `); @@ -183,8 +187,9 @@ function umd(script, deps, exp, filename) { let name = nameFromDependency(dep); commonjs.push(` - if (! window.DataTable.${name}) { - require('${dep}')(root); + baseModule['${dep}'] = require('${dep}'); + if (! root.DataTable.${name}) { + root.DataTable.${name} = cjsModules['${dep}'](root); } `); } @@ -221,6 +226,7 @@ function umd(script, deps, exp, filename) { } else if (typeof exports === 'object') { // CommonJS + var cjsModules = ${commonjsmodules}; var cjsRequires = function (root) {${commonjs.join('')} }; if (typeof window === 'undefined') { From c98858c7cd018f2c3503ef85fd8410f66dc8b063 Mon Sep 17 00:00:00 2001 From: Jamie Lentin Date: Wed, 29 Jul 2026 10:14:55 +0000 Subject: [PATCH 2/2] Fix: Use global window, instead of relying on global location In windowless environments (read: nodejs), location will not be defined. However, the CommonJS wrapper makes sure window & document are defined appropriately in these scenarios. References: https://github.com/DataTables/DataTablesSrc/issues/385 --- js/util/ajax.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/util/ajax.ts b/js/util/ajax.ts index 1a2d430e..e99417dc 100644 --- a/js/util/ajax.ts +++ b/js/util/ajax.ts @@ -44,7 +44,7 @@ const defaults = { contentType: 'application/x-www-form-urlencoded; charset=UTF-8', headers: {}, traditional: false, - url: location.href + url: window.location.href } as AjaxOptions; /**