OrchardCMS/OrchardCore · error · Error
withCredentials option was not a 'boolean' or 'undefined'…
Error message
withCredentials option was not a 'boolean' or 'undefined' value
What it means
HttpConnection options validation throws this when the withCredentials option is provided but is not a boolean or undefined. The library defaults withCredentials to true, but any explicitly wrong-typed value (string, number, object) is rejected at connection construction rather than coerced.
Solutions
- Pass a real boolean: withCredentials: true or withCredentials: false.
- Coerce config values before use with Boolean(value) or value === "true".
- Omit the option entirely to accept the default (true).
- Fix the serialization layer so booleans survive JSON parsing as booleans.
Example fix
// before
new signalR.HubConnectionBuilder()
.withUrl("/hub", { withCredentials: "true" }) // throws
.build();
// after
const raw = getConfig("withCredentials");
new signalR.HubConnectionBuilder()
.withUrl("/hub", { withCredentials: raw === undefined ? undefined : raw === true || raw === "true" })
.build(); Defensive patterns
Strategy: type-guard
Validate before calling
function assertWithCredentials(v) {
if (v !== undefined && typeof v !== "boolean") {
throw new TypeError(`withCredentials must be boolean, got ${typeof v}`);
}
} Type guard
function isWithCredentialsValid(v) {
return v === undefined || typeof v === "boolean";
} Try / catch
try {
const conn = builder.withUrl(url, { withCredentials }).build();
} catch (err) {
if (err.message.includes("withCredentials option")) {
console.error("withCredentials must be a boolean — check config parsing");
} else { throw err; }
} Prevention
- Keep SignalR option objects defined in code, not parsed from strings.
- Coerce config booleans explicitly (=== "true") before passing options.
- Use TypeScript so withCredentials is typed as boolean | undefined.
- Add a unit test that builds the connection from your real config source.
When it happens
Trigger: Passing { withCredentials: "true" } or { withCredentials: 1 } to withUrl(url, options), or building options from parsed JSON/config where the value arrives as a string instead of a boolean.
Common situations: Reading options from query-string/config JSON where booleans deserialize as strings; copying option objects between HTTP libraries with different coercion rules; typos like withCredentials: 'false'.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- A Content Item was expected
- Binary protocols over XmlHttpRequest not implementing…
- could not find global
- Detected a connection attempt to an ASP.NET SignalR Server…
- DisplayAsync requires an instance of IShape
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/69d05bf46aec26c0.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.SignalR/wwwroot/Scripts/signalr.js:2700
const MAX_REDIRECTS = 100;
/** @private */
class HttpConnection {
constructor(url, options = {}) {
this._stopPromiseResolver = () => { };
this.features = {};
this._negotiateVersion = 1;
Arg.isRequired(url, "url");
this._logger = createLogger(options.logger);
this.baseUrl = this._resolveUrl(url);
options = options || {};
options.logMessageContent = options.logMessageContent === undefined ? false : options.logMessageContent;
if (typeof options.withCredentials === "boolean" || options.withCredentials === undefined) {
options.withCredentials = options.withCredentials === undefined ? true : options.withCredentials;
}
else {
throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");
}
options.timeout = options.timeout === undefined ? 100 * 1000 : options.timeout;
let webSocketModule = null;
let eventSourceModule = null;
if (Platform.isNode && "function" !== "undefined") {
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
const requireFunc = true ? require : 0;
webSocketModule = requireFunc("ws");
eventSourceModule = requireFunc("eventsource");
}
if (!Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {
options.WebSocket = WebSocket;
}
else if (Platform.isNode && !options.WebSocket) {
if (webSocketModule) {
options.WebSocket = webSocketModule;
}View on GitHub (pinned to 4306c0717f)