Netlify functions work on localhost but not in production

Hi! I am new with Netlify functions and started to build this website to learn how to implement serverless configuration inside a react app (https://netlify-functions-with-react.netlify.app/). The repo can be found here (GitHub - AlexCo888/netlify-functions: I created this website to learn Netlify Serverless Functions with React using Netlify CLI) and I used create-react-app to build it.

Everything works completely fine on localhost (using Netlify CLI → netlify dev) . Nevertheless, when I deployed the app on production I can’t get access to this URL (https://netlify-functions-with-react.netlify.app/airtable). I received “Failed to load resource: the server responded with a status of 500 ()” from the console.

I am using Airtable’s API and, as I shared before, everything works completely fine on with netlify dev (http://localhost:8888/airtable).

I thought it was something related to CORS and headers but after trying different things that I saw in several netlify community posts I still can’t get my app running well on production.

I will be grateful if someone can give me some advice to understand better what is happening.

Hey @JuanB2019

The function itself is returning a 500 Error because that is what is programmed in the catch

catch (error) {
    return {
      statusCode: 500,
      body: JSON.stringify(error),
    };
  }

This means the call to Airbase is failing.

Have you correctly set the AIRTABLE_API_KEY and AIRTABLE_BASE_ID environment variables in the Netlify UI?

Thank you very much for your quick response Coel!

Effectively this was the problem. I thought that “netlify deploy” would automatically insert env variables. I appreciate a lot your time and attention :slight_smile: