dotnet/aspnetcore · error · Error

The ' ' argument is required.

Error message

The '${name}' argument is required.

What it means

Thrown by Arg.isRequired when a required argument is null or undefined. It is the standard precondition guard used across the TS client - HubConnectionBuilder.withUrl/withHubProtocol/withHubProtocol/configureLogging, HttpConnection, WebSocketTransport, LongPollingTransport, ServerSentEventsTransport all validate their inputs through it. The ${name} token is the human-readable argument name supplied at each call site.

Solutions

  1. Check the stack trace - the ${name} in the message names the exact missing argument (e.g. 'url', 'connection', 'protocol', 'logger').
  2. Ensure the value is set before passing it: load and validate configuration (env var / config file) before calling the builder.
  3. Default the value where sensible, e.g. url = process.env.HUB_URL ?? throwOnMissing(), never pass undefined.
  4. Confirm every required builder method is called: withUrl, withHubProtocol (or default JsonHubProtocol), configureLogging.

Example fix

// before
const conn = new HubConnectionBuilder()
  .withUrl(hubUrl) // hubUrl is undefined when env var missing
  .build();

// after
if (!hubUrl) throw new Error('HUB_URL env var is required');
const conn = new HubConnectionBuilder().withUrl(hubUrl).build();
Defensive patterns

Strategy: validation

Validate before calling

function assertRequired<T>(value: T | null | undefined, name: string): asserts value is T {
  if (value === null || value === undefined) {
    throw new Error(`Pre-check failed: '${name}' is required.`);
  }
}

assertRequired(hubUrl, 'url');
const conn = new HubConnectionBuilder().withUrl(hubUrl).build();

Type guard

function isPresent<T>(value: T | null | undefined): value is T {
  return value !== null && value !== undefined;
}

Try / catch

try {
  const conn = new HubConnectionBuilder()
    .withUrl(url)
    .withHubProtocol(protocol)
    .configureLogging(logger)
    .build();
} catch (e) {
  if (e instanceof Error && /argument is required/.test(e.message)) {
    // the ${name} in the message tells you which one; fix the config source
  } else throw e;
}

Prevention

When it happens

Trigger: Calling HubConnectionBuilder.withUrl(null) or .withUrl(undefined); constructing HubConnection without a connection/logger/protocol; building a transport with an unset url or transferFormat; passing an undefined configurer to configureLogging.

Common situations: Reading the hub URL from an env var/config that is not set (returns undefined); calling builder methods in the wrong order so a later step overwrites a value with undefined; tree-shaking or partial imports leaving a dependency undefined; refactoring that renames a variable but leaves the old null-valued one in the builder chain.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/5d06e3e1210ea206. Report an issue: GitHub.

Appendix: source

Thrown at src/SignalR/clients/ts/signalr/src/Utils.ts:20

// The .NET Foundation licenses this file to you under the MIT license.

import { HttpClient } from "./HttpClient";
import { ILogger, LogLevel } from "./ILogger";
import { NullLogger } from "./Loggers";
import { IStreamSubscriber, ISubscription } from "./Stream";
import { Subject } from "./Subject";
import { IHttpConnectionOptions } from "./IHttpConnectionOptions";
import { VERSION } from "./pkg-version";

// Version token that will be replaced by the prepack command
/** The version of the SignalR client. */

export { VERSION };
/** @private */
export class Arg {
    public static isRequired(val: any, name: string): void {
        if (val === null || val === undefined) {
            throw new Error(`The '${name}' argument is required.`);
        }
    }
    public static isNotEmpty(val: string, name: string): void {
        if (!val || val.match(/^\s*$/)) {
            throw new Error(`The '${name}' argument should not be empty.`);
        }
    }

    public static isIn(val: any, values: any, name: string): void {
        // TypeScript enums have keys for **both** the name and the value of each enum member on the type itself.
        if (!(val in values)) {
            throw new Error(`Unknown ${name} value: ${val}.`);
        }
    }
}

/** @private */
export class Platform {

View on GitHub (pinned to 3600ca084e)