appwrite / sdk-for-web

[READ-ONLY] Official Appwrite Web SDK 🧑
https://appwrite.io
BSD 3-Clause "New" or "Revised" License
293 stars 62 forks source link

πŸ› Bug Report: ReferenceError: fetch is not defined #106

Closed Edijae closed 1 month ago

Edijae commented 1 month ago

πŸ‘Ÿ Reproduction steps

import {Client, Account, Databases, Storage} from 'appwrite';

let webClient = new Client();
        webClient.setEndpoint(endpoint)
        .setProject(project)

let webAccount = new Account(webClient);

let session = await webAccount.createEmailPasswordSession(email, password);

πŸ‘ Expected behavior

I should succesfully create a session.

πŸ‘Ž Actual Behavior

ReferenceError: fetch is not defined
    at Client.<anonymous> (file:///app/node_modules/appwrite/src/client.ts:691:26)
    at Generator.next (<anonymous>)
    at file:///app/node_modules/appwrite/node_modules/tslib/tslib.es6.js:76:71
    at new Promise (<anonymous>)
    at __awaiter (file:///app/node_modules/appwrite/node_modules/tslib/tslib.es6.js:72:12)
    at Client.call (file:///app/node_modules/appwrite/dist/esm/sdk.js:624:16)
    at Account.<anonymous> (file:///app/node_modules/appwrite/src/services/account.ts:871:34)
    at Generator.next (<anonymous>)
    at file:///app/node_modules/appwrite/node_modules/tslib/tslib.es6.js:76:71
    at new Promise (<anonymous>)

🎲 Appwrite version

Version 0.10.x

πŸ’» Operating system

Linux

🧱 Your Environment

using node v22.8.0

appwrite library v16.0.0

πŸ‘€ Have you spent some time to check if this issue has been raised before?

🏒 Have you read the Code of Conduct?

Edijae commented 1 month ago

i solved the bug by adding

import fetch from "node-fetch";
global.fetch = fetch;

in my index.ts file to make fetch available globally for libraries that depend on it