{"record":{"id":"1cbfc6518d5e2e6a","repo":"dotnet/runtime","slug":"no-fetch-implementation-available-1cbfc6","errorCode":null,"errorMessage":"No fetch implementation available","messagePattern":"No fetch implementation available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/native/libs/Common/JavaScript/loader/polyfills.ts","lineNumber":136,"sourceCode":"            const isText = expectedContentType && (expectedContentType.startsWith(\"application/json\") || expectedContentType.startsWith(\"text/plain\"));\n            const arrayBuffer = read(url, isText ? \"utf8\" : \"binary\");\n            return responseLike(url, arrayBuffer, {\n                status: 200,\n                statusText: \"OK\",\n                headers: {\n                    \"Content-Length\": isText ? arrayBuffer.length : arrayBuffer.byteLength.toString(),\n                    \"Content-Type\": expectedContentType || \"application/octet-stream\"\n                }\n            });\n        }\n    } catch (e: any) {\n        return responseLike(url, null, {\n            status: 500,\n            statusText: \"ERR28: \" + e,\n            headers: {},\n        });\n    }\n    throw new Error(\"No fetch implementation available\");\n}\n\nexport function responseLike(url: string, body: ArrayBuffer | string | null, options: ResponseInit): Response {\n    if (typeof globalThis.Response === \"function\") {\n        const response = new Response(body, options);\n\n        // Best-effort alignment with the fallback object shape:\n        // only define `url` if it does not already exist on the response.\n        if (typeof (response as any).url === \"undefined\") {\n            try {\n                Object.defineProperty(response, \"url\", { value: url });\n            } catch {\n                // Ignore if the implementation does not allow redefining `url`\n            }\n        }\n\n        return response;\n    }","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/Common/JavaScript/loader/polyfills.ts#L118-L154","documentation":"fetchLike (loader/polyfills.ts) is the last-resort fetch implementation. It tries: Node fs for file:// and missing-fetch cases, globalThis.fetch in browser/node, and the global read() function in JS shells. If none of these branches apply (no fetch, not Node, no read), it throws 'No fetch implementation available'.","triggerScenarios":"Booting the loader in an environment that has no globalThis.fetch, is not detected as Node (so _nodeFs is undefined), and does not provide a global read() function. The loader cannot download any asset.","commonSituations":"Running inside an embedded/worker runtime that stripped fetch; a test harness (jsdom) without fetch configured; a sandboxed VM context missing both fetch and require; a custom host that set ENVIRONMENT_IS_NODE=false but did not provide fetch.","solutions":["Provide globalThis.fetch before bootstrapping: install node-fetch, undici, or the host's native fetch.","If running under Node, ensure ENVIRONMENT_IS_NODE detection works (process.versions.node present) so the fs branch engages.","For JS shells, expose a global read() function compatible with the emscripten signature.","Use a loadBootResource callback (withResourceLoader) to supply your own fetch returning Response objects."],"exampleFix":"// before — no fetch in custom host\nconst dotnet = await dotnet.create(); // throws 'No fetch implementation available'\n\n// after — install fetch\nconst fetch = require('node-fetch');\nglobalThis.fetch = fetch;\nconst dotnet = await dotnet.create();","handlingStrategy":"fallback","validationCode":"if (typeof globalThis.fetch !== 'function' && typeof globalThis.require !== 'function') {\n  throw new Error('No fetch detected — install node-fetch or provide a global fetch before boot');\n}","typeGuard":"function hasFetch(g: any): g is { fetch: typeof fetch } {\n  return typeof g?.fetch === 'function';\n}","tryCatchPattern":null,"preventionTips":["Install and assign globalThis.fetch before importing the runtime.","Ensure Node detection (process.versions.node) is intact for the fs fallback.","In custom hosts, provide either fetch or a global read() function."],"tags":["network","fetch","environment","polyfill","runtime"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}