Fin Moorhouse
Fin Moorhouse

Reputation: 335

Error with Lambda Function running on NodeJS netlify-lambda — "TypeError: Expected signal to be an instanceof AbortSignal"

I’ve recently been trying to set up a Lambda Function on a Netlify site. The rest of the site is running on Gatsby. I’m able to get some basic functions working in development and production (e.g. returning a “hello world”), but I’m running into a problem whenever I try something more complex.

My function always seems to return an error in development which says Function invocation failed: TypeError: Expected signal to be an instanceof AbortSignal. I haven’t tried getting it to work in production (although it obviously won’t work as it stands, relying on .env). I'm using netlify-lambda for this.

For instance, here is the code I’m trying to get to work, lifted from this gist. I'm trying to fetch records from a simple Airtable database using their API.

require("dotenv").config({ debug: process.env.DEBUG })


const Airtable = require("airtable")
Airtable.configure({
  endpointUrl: "https://api.airtable.com",
  apiKey: process.env.AIRTABLE_PASS,
})
var base = Airtable.base(process.env.AIRTABLE_ID)

exports.handler = function(event, context, callback) {
  const allRecords = []
  base('Main')
    .select({
      maxRecords: 100,
      view: 'all'
    })
    .eachPage(
      function page(records, fetchNextPage) {
        records.forEach(function(record) {
          allRecords.push(record)
        })
        fetchNextPage()
      },
      function done(err) {
        if (err) {
          callback(err)
        } else {
          const body = JSON.stringify({ records: allRecords })
          const response = {
            statusCode: 200,
            body: body,
            headers: {
              'content-type': 'application/json',
              'cache-control': 'Cache-Control: max-age=300, public'
            }
          }
          callback(null, response)
        }
      }
    )
}

The error occurs whether I hit the url from my browser, or send a GET or POST request through Postman or a form.

The Netlify site name is affectionate-engelbart-b6885d, and the repo is here.

Happy to post error logs if that’s helpful. Thank you!

Upvotes: 0

Views: 2018

Answers (1)

key
key

Reputation: 21

Downgrade airtable to version 0.8.1.

I had the same issue. I found this helpful.

Upvotes: 2

Related Questions