Airtable/airtable.js

airtable.js does not support Deno

isaced opened this issue · 6 comments

I tried to use airtable.js with deno, but it did not work. I got an error message saying "Uncaught TypeError: Invalid URL...". I also tried to use airtable-deno, but it had many issues and was not updated for a long time. I hope airtable.js can support deno in the future.

Here is my code:

import Airtable from "npm:airtable";
const base = new Airtable({ apiKey: Deno.env.get('AIRTABLE_API_KEY') }).base('XXXXXX');

base('News').select({
    view: 'Grid view'
}).firstPage(function (err, records) {
    if (err) { console.error(err); return; }
    records?.forEach(function (record) {
        console.log('Retrieved', record.get('title'));
    });
});

This is the error that Deno reports when running:

error: Uncaught TypeError: Invalid URL: ''
    at getSerialization (internal:ext/url/00_url.js:76:13)
    at opUrlParse (internal:ext/url/00_url.js:67:12)
    at new URL (internal:ext/url/00_url.js:365:29)
    at new Request (internal:ext/fetch/23_request.js:321:27)
    at Object.<anonymous> (file:///Users/isaced/Library/Caches/deno/npm/registry.npmmirror.com/airtable/0.11.6/lib/abort-controller.js:8:22)
    at Object.<anonymous> (file:///Users/isaced/Library/Caches/deno/npm/registry.npmmirror.com/airtable/0.11.6/lib/abort-controller.js:19:4)
    at Module._compile (internal:ext/node/02_require.js:747:36)
    at Object.Module._extensions..js (internal:ext/node/02_require.js:780:12)
    at Module.load (internal:ext/node/02_require.js:658:34)
    at Function.Module._load (internal:ext/node/02_require.js:515:14)

} else if ('signal' in new Request('')) {

same for me, trying to run this in Deno Deploy

import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
// import "https://esm.sh/airtable-json?pin=v2.1.2";
import "https://esm.sh/airtable"; 

async function reqHandler() {

  var base = new Airtable({apiKey : 'key9SLnjxxxxxk8IN'}).base('appbvxxxxxKE02S');
  var result : string[] = [];
  base('Table 1').select({
    // Selecting the first 3 records in Grid view:
    maxRecords: 3,
    view: "Grid view"
  }).eachPage(function page(records, fetchNextPage) {
      // This function (`page`) will get called for each page of records.

      records.forEach(function(record) {
          let a = record.get('Domain');
          console.log('Retrieved', a);
          result.push(a);
      });

      fetchNextPage();

  }, function done(err) {
      if (err) { console.error(err); return; }
  });

  const body = JSON.stringify(result);
  return new Response(body, {
    headers: { "content-type": "application/json; charset=utf-8" },
  });

}

@isaced this worked for me #242 (comment)

@goryny4 It looks like airtable-dnd and airtable-deno are not maintained anymore (last updated 3 years ago).

airtable-dnd and airtable-deno versions are not based on airtable approach and work chaotically.
According to this issue they are looking for new maintainers.

These days, deno grows up and is important to supporting Deno for dev community, i would like to raise up this topic and discuss possibilities to use Airtable.js for Deno environment.