Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use in a Cloudflare Worker #242

Open
jaymakes11 opened this issue Dec 28, 2020 · 3 comments
Open

Can't use in a Cloudflare Worker #242

jaymakes11 opened this issue Dec 28, 2020 · 3 comments

Comments

@jaymakes11
Copy link

jaymakes11 commented Dec 28, 2020

When trying to use via a Cloudflare Worker (https://workers.cloudflare.com/), I get:

TypeError: c.default is not a constructor
    at Object.t [as default] (worker.js:1:95829)
    at t.runAction (worker.js:1:64890)
    at t._createRecords (worker.js:1:20673)
    at worker.js:1:9086
    at new Promise (<anonymous>)
    at t.create (worker.js:1:9020)
    at worker.js:1:96859
    at o (worker.js:1:96877)
    at async worker.js:1:97295
@jaymakes11
Copy link
Author

jaymakes11 commented Dec 28, 2020

The runtime for Cloudflare Workers is not browser or node, which I suspect is the issue here. It uses the V8 JS engine directly (https://developers.cloudflare.com/workers/runtime-apis/web-standards). This means it doesn't have access to some runtime APIs that are available in Node.

Hoping this is not a blocker for being able to run Airtable in Cloudflare Workers.

@jaymakes11
Copy link
Author

jaymakes11 commented Dec 29, 2020

Posted this in the Cloudflare forum. Findings (from here https://community.cloudflare.com/t/cant-use-airtable-from-worker/232590/2):

The problem looks to be that it’s trying to grab window.fetch, which isn’t possible within a service worker, and then defaulting to nodeFetch if that’s not available.

If that is, indeed, the case, this seems similar to the previous problems FaunaDB's JS driver was having in Cloudflare Workers. There's already a fetch method available to workers, so the solution they took was to allow passing in a custom fetch handler when initiating the client. See here: fauna/faunadb-js#207

Perhaps the same approach would work here?

@rcotrina94
Copy link

rcotrina94 commented Jan 15, 2022

I ended up using airtable-dnd, an "Unofficial Airtable API client for Node.js ported from airtable-deno" as it internally uses fetch and assumes it exists. API is quite similar to @Airtable/airtable.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants