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

Hi all, I’ve recently been trying to set up a Lambda Function on my 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).

For instance, here is the code I’m trying to get to work, lifted from this gist.

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 site name is affectionate-engelbart-b6885d.

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

hi there,

a quick google shows me that this seems to be a not uncommon error:

https://www.google.com/search?q=Function+invocation+failed%3A+TypeError%3A+Expected+signal+to+be+an+instanceof+AbortSignal.&oq=Function+invocation+failed%3A+TypeError%3A+Expected+signal+to+be+an+instanceof+AbortSignal.&aqs=chrome..69i57.383j0j7&sourceid=chrome&ie=UTF-8

I think that this is likely to be a little bit beyond what we can debug with you - but I am definitely going to leave this post open so others can weigh in!

Thanks for your help perry. I suppose it’s useful to know that this isn’t a Netlify-specific issue. I’ll see if I can make sense of the other threads on the topic (although I didn’t have a great deal of luck earlier).

2 Likes

Any luck with this? I’m using the airtable API in a lambda function with serverless framework and running into the same issue.

Sadly not, I’m afraid! Switched to Netlify forms instead (which is now working nicely, for what it’s worth).

2 Likes

So I was using webpack to package my Lambda before deploy, and based on some other S/O posts I saw, this was likely causing the problem. LSS, I couldn’t configure it in a way to prevent minimization and sidestep the error.

I rebuilt my proxy server without webpack and the error went away. I’m curious if you were also using webpack?

1 Like

Yes, I’m aware it’s a webpack issue — unfortunately the site was running on Gatsby, which uses webpack. Fortunately I found a nice workaround using Netlify forms! Glad to hear you managed to get it fixed also.