{"record":{"id":"6b245b15b8adc1f8","repo":"dotnet/runtime","slug":"please-install-node-fetch-and-node-abort-contro","errorCode":null,"errorMessage":"Please install `node-fetch` and `node-abort-controller` npm packages to enable HTTP client support.","messagePattern":"Please install `node-fetch` and `node-abort-controller` npm packages to enable HTTP client support\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/http.ts","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT license.\n\nimport BuildConfiguration from \"consts:configuration\";\n\nimport { wrap_as_cancelable_promise } from \"./cancelable-promise\";\nimport { ENVIRONMENT_IS_NODE, loaderHelpers, mono_assert } from \"./globals\";\nimport { assert_js_interop } from \"./invoke-js\";\nimport { MemoryViewType, Span } from \"./marshal\";\nimport type { VoidPtr } from \"./types/emscripten\";\nimport { ControllablePromise } from \"./types/internal\";\nimport { mono_log_debug } from \"./logging\";\n\n\nfunction verifyEnvironment () {\n    if (typeof globalThis.fetch !== \"function\" || typeof globalThis.AbortController !== \"function\") {\n        const message = ENVIRONMENT_IS_NODE\n            ? \"Please install `node-fetch` and `node-abort-controller` npm packages to enable HTTP client support.\"\n            : \"This browser doesn't support fetch API. Please use a modern browser. See also https://learn.microsoft.com/aspnet/core/blazor/supported-platforms\";\n        throw new Error(message);\n    }\n}\n\nfunction commonAsserts (controller: HttpController) {\n    assert_js_interop();\n    mono_assert(controller, \"expected controller\");\n}\n\nexport function http_wasm_supports_streaming_request (): boolean {\n    // Detecting streaming request support works like this:\n    // If the browser doesn't support a particular body type, it calls toString() on the object and uses the result as the body.\n    // So, if the browser doesn't support request streams, the request body becomes the string \"[object ReadableStream]\".\n    // When a string is used as a body, it conveniently sets the Content-Type header to text/plain;charset=UTF-8.\n    // So, if that header is set, then we know the browser doesn't support streams in request objects, and we can exit early.\n    // 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.\n    // See https://developer.chrome.com/articles/fetch-streaming-requests/\n    if (typeof Request !== \"undefined\" && \"body\" in Request.prototype && typeof ReadableStream === \"function\" && typeof TransformStream === \"function\") {\n        let duplexAccessed = false;","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/http.ts#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"Upgrading a library that now exercises HttpClient under Node; CI running on Node 16; a Node host where fetch was deleted from globalThis.","solutions":["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 = ...","Upgrade to NodeJS 18+ which provides fetch and AbortController natively.","Avoid calling HttpClient from .NET code running under old NodeJS."],"exampleFix":"// before: Node 16 with no polyfills\n// after:\nconst fetch = require('node-fetch');\nconst { AbortController } = require('node-abort-controller');\nglobalThis.fetch = fetch;\nglobalThis.AbortController = AbortController;","handlingStrategy":"type-guard","validationCode":"// before creating the runtime under Node\nif (typeof globalThis.fetch !== 'function' || typeof globalThis.AbortController !== 'function') {\n  require('node-fetch/polyfill');\n  require('node-abort-controller/polyfill');\n}","typeGuard":"function hasHttpGlobals(): boolean {\n  return typeof globalThis.fetch === 'function' && typeof globalThis.AbortController === 'function';\n}","tryCatchPattern":null,"preventionTips":["Pin NodeJS to 18+ for native fetch/AbortController.","If you must use Node 16, install and register node-fetch and node-abort-controller polyfills before booting.","Gate HttpClient usage in tests on hasHttpGlobals()."],"tags":["node","http","fetch","polyfill","abort-controller"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}