dotnet/aspnetcore · error

No method defined.

Error message

No method defined.

What it means

Thrown by FetchHttpClient.send() when request.method is falsy (undefined/empty). Before issuing the fetch, the client requires an explicit HTTP verb. This is also checked in DefaultHttpClient.send (which rejects with the same message), so it surfaces from either entry point. It indicates the HttpRequest was built without setting a method.

Source

Thrown at src/SignalR/clients/ts/signalr/src/FetchHttpClient.ts:66

            // @ts-ignore: TS doesn't know about these names
            const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;

            // Node needs EventListener methods on AbortController which our custom polyfill doesn't provide
            this._abortControllerType = requireFunc("abort-controller");
        } else {
            this._abortControllerType = AbortController;
        }
    }

    /** @inheritDoc */
    public async send(request: HttpRequest): Promise<HttpResponse> {
        // Check that abort was not signaled before calling send
        if (request.abortSignal && request.abortSignal.aborted) {
            throw new AbortError();
        }

        if (!request.method) {
            throw new Error("No method defined.");
        }
        if (!request.url) {
            throw new Error("No url defined.");
        }

        const abortController = new this._abortControllerType();

        let error: any;
        // Hook our abortSignal into the abort controller
        if (request.abortSignal) {
            request.abortSignal.onabort = () => {
                abortController.abort();
                error = new AbortError();
            };
        }

        // If a timeout has been passed in, setup a timeout to call abort
        // Type needs to be any to fit window.setTimeout and NodeJS.setTimeout

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Use the HttpClient.get/post/delete helpers which set the method automatically instead of calling send directly.
  2. If calling send directly, always set request.method to a valid HTTP verb.
  3. Validate the request object before sending: assert request.method.
  4. Add a TypeScript check by typing the argument as HttpRequest and ensuring method is provided.

Example fix

// before
await httpClient.send({ url: 'https://example.com' });

// after
await httpClient.get('https://example.com');
// or
await httpClient.send({ method: 'GET', url: 'https://example.com' });
Defensive patterns

Strategy: validation

Validate before calling

function assertRequest(req: { method?: string; url?: string }) {
  if (!req.method) throw new Error('HttpRequest.method is required');
  if (!req.url) throw new Error('HttpRequest.url is required');
}
assertRequest(request);
await httpClient.send(request);

Type guard

function hasMethod(req: { method?: string }): req is { method: string } {
  return typeof req.method === 'string' && req.method.length > 0;
}

Try / catch

try {
  await httpClient.send(request);
} catch (e) {
  if (e.message === 'No method defined.') {
    throw new Error('Build the HttpRequest with an HTTP method (use httpClient.get/post helpers)');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling httpClient.send({ url: 'https://x' }) with no method; passing an HttpRequest whose method is an empty string; a helper that spreads options but forgets method.

Common situations: Direct use of HttpClient.send without going through get/post helpers (which set the method); a custom HttpClient wrapper that drops the method field; malformed request building.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/a9648fc68eb2fec4. Report an issue: GitHub.