dotnet/runtime · error · Error

Please install `node-fetch` and `node-abort-controller` npm…

Error message

Please install `node-fetch` and `node-abort-controller` npm packages to enable HTTP client support.

What it means

Thrown by verifyEnvironment in http.ts when running under NodeJS (ENVIRONMENT_IS_NODE) and either globalThis.fetch or globalThis.AbortController is not a function. The HttpClient in the wasm runtime needs both APIs; on NodeJS versions that predate the built-in fetch (<18), the runtime expects the node-fetch and node-abort-controller polyfills to be installed and registered.

Solutions

  1. Install and register node-fetch and node-abort-controller before creating the runtime: npm install node-fetch node-abort-controller and globalThis.fetch = ...; globalThis.AbortController = ...
  2. Upgrade to NodeJS 18+ which provides fetch and AbortController natively.
  3. Avoid calling HttpClient from .NET code running under old NodeJS.

Example fix

// before: Node 16 with no polyfills
// after:
const fetch = require('node-fetch');
const { AbortController } = require('node-abort-controller');
globalThis.fetch = fetch;
globalThis.AbortController = AbortController;
Defensive patterns

Strategy: type-guard

Validate before calling

// before creating the runtime under Node
if (typeof globalThis.fetch !== 'function' || typeof globalThis.AbortController !== 'function') {
  require('node-fetch/polyfill');
  require('node-abort-controller/polyfill');
}

Type guard

function hasHttpGlobals(): boolean {
  return typeof globalThis.fetch === 'function' && typeof globalThis.AbortController === 'function';
}

Prevention

When it happens

Trigger: Calling http_wasm_create_controller or http_wasm_fetch on NodeJS 14/16 without polyfills; running the .NET wasm runtime under an old NodeJS host that uses HttpClient; using a test harness (Jest on old Node) that does not expose global fetch.

Common situations: Upgrading a library that now exercises HttpClient under Node; CI running on Node 16; a Node host where fetch was deleted from globalThis.

Related errors


AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10). Data as JSON: /api/errors/6b245b15b8adc1f8. Report an issue: GitHub.

Appendix: source

Thrown at src/mono/browser/runtime/http.ts:20

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

import BuildConfiguration from "consts:configuration";

import { wrap_as_cancelable_promise } from "./cancelable-promise";
import { ENVIRONMENT_IS_NODE, loaderHelpers, mono_assert } from "./globals";
import { assert_js_interop } from "./invoke-js";
import { MemoryViewType, Span } from "./marshal";
import type { VoidPtr } from "./types/emscripten";
import { ControllablePromise } from "./types/internal";
import { mono_log_debug } from "./logging";


function verifyEnvironment () {
    if (typeof globalThis.fetch !== "function" || typeof globalThis.AbortController !== "function") {
        const message = ENVIRONMENT_IS_NODE
            ? "Please install `node-fetch` and `node-abort-controller` npm packages to enable HTTP client support."
            : "This browser doesn't support fetch API. Please use a modern browser. See also https://learn.microsoft.com/aspnet/core/blazor/supported-platforms";
        throw new Error(message);
    }
}

function commonAsserts (controller: HttpController) {
    assert_js_interop();
    mono_assert(controller, "expected controller");
}

export function http_wasm_supports_streaming_request (): boolean {
    // Detecting streaming request support works like this:
    // If the browser doesn't support a particular body type, it calls toString() on the object and uses the result as the body.
    // So, if the browser doesn't support request streams, the request body becomes the string "[object ReadableStream]".
    // When a string is used as a body, it conveniently sets the Content-Type header to text/plain;charset=UTF-8.
    // So, if that header is set, then we know the browser doesn't support streams in request objects, and we can exit early.
    // Safari does support streams in request objects, but doesn't allow them to be used with fetch, so the duplex option is tested, which Safari doesn't currently support.
    // See https://developer.chrome.com/articles/fetch-streaming-requests/
    if (typeof Request !== "undefined" && "body" in Request.prototype && typeof ReadableStream === "function" && typeof TransformStream === "function") {
        let duplexAccessed = false;

View on GitHub (pinned to 60108ba66e)