-
Notifications
You must be signed in to change notification settings - Fork 515
Closed
Labels
Description
Chore
Describe the chore
Request update the static import of @supabase/node-fetch in src/PostgrestBuilder:
Use dynamic import('@supabase/node-fetch') to avoid possible Cannot read property 'bind' of undefined error.
Additional context
When using @supabase/supabase-js which requires @supabase/postgrest-js, a user is able to provide custom fetch by providing a global.fetch option. However, with @supabase/node-fetch statically imported in @supabase/postgrest-js, a Cannot read property 'bind' of undefined error may throw at runtime.
TypeError: Cannot read property 'bind' of undefined
at path/to/node_modules/@supabase/node-fetch/browser.js
The error is thrown when the runtime environment does not have native fetch on globalObject at all.
/* @supabase/node-fetch/browser.js#L18 */
export default globalObject.fetch.bind(globalObject);In some other @supabase/ packages like @supabase/auth-js, the fetch is resolved using a resolveFetch function:
/* @supabase/auth-js/src/lib/helpers.ts#L93-L104. */
export const resolveFetch = (customFetch?: Fetch): Fetch => {
let _fetch: Fetch
if (customFetch) {
_fetch = customFetch
} else if (typeof fetch === 'undefined') {
_fetch = (...args) =>
import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
} else {
_fetch = fetch
}
return (...args) => _fetch(...args)
}This way, the node-fetch import is safe.
soedirgo