nodeRequire function
Loads a CommonJS module from Node.js.
Throws UnsupportedError on non-Node JS hosts (browsers, workers, etc.)
because globalThis.require is only provided by Node's module loader.
Implementation
JSObject nodeRequire(String moduleId) {
if (!isNodeRuntime()) {
throw UnsupportedError(
'nodeRequire("$moduleId") is only available when running under '
'Node.js. Current host has no `globalThis.process.versions.node`.',
);
}
final mod = _requireRaw(moduleId.toJS);
if (mod == null) {
throw StateError('Node `require("$moduleId")` returned null / undefined.');
}
return mod as JSObject;
}