bluesky-social / atproto

Social networking technology created by Bluesky
Other
6.48k stars 452 forks source link

atproto/api - XRPCError: ReferenceError: fetch is not defined #968

Closed pkayfire closed 1 year ago

pkayfire commented 1 year ago

Getting the following error when trying to use the atproto/api module:

XRPCError: ReferenceError: fetch is not defined
    at Function.defaultFetchHandler [as fetch] (/Users/pkayfire/Workspace/moonlab/perl-backend/node_modules/@atproto/xrpc/src/client.ts:156:11)
    at BskyAgent._fetch (/Users/pkayfire/Workspace/moonlab/perl-backend/node_modules/@atproto/api/src/agent.ts:201:30)
    at async ServiceClient.call (/Users/pkayfire/Workspace/moonlab/perl-backend/node_modules/@atproto/xrpc/src/client.ts:104:17)
    at async BskyAgent.login (/Users/pkayfire/Workspace/moonlab/perl-backend/node_modules/@atproto/api/src/agent.ts:120:19)
    at async file:///Users/pkayfire/Workspace/moonlab/perl-backend/scripts/bluesky/test.ts:15:18 {
  status: 1,
  error: 'ReferenceError: fetch is not defined',
  success: false
}
dholms commented 1 year ago

are you in react native?

could be this: https://github.com/bluesky-social/atproto/issues/667

there's an example fetch polyfill here: https://github.com/bluesky-social/atproto/blob/main/packages/api/docs/rn-fetch-handler.ts

pkayfire commented 1 year ago

On a Node backend, looks like you need at least version 18 to have fetch globally.