Deployment issues with Netlify Functions using CRA

Hi everyone!

I was testing Netlify functions with Create-React-App and ran into deployment issues. The app works perfectly fine in development mode, and in production, the front-end (built with CRA) works as expected but the backend is returning a 500 error.

The site can be found here and it was bootstrapped using this repository GitHub - Kirbyasdf/netlify-react-lambda-node-boilerplate: 1click deploy *now with node/express option. The endpoint like this one isn’t working properly. I can see in the Netlify UI that the functions are deployed, but they aren’t being invoked even if I hit the correct endpoint.

Could someone look into it and tell me what I’m doing wrong? It would be very much appreciated.

Thank you very much.

Hi @yutamoridev,

The website seems to be using manual deployments. How are you deploying it? Using the CLI?

Hi @hrishikesh, thank you for getting back to me. Yes, I deployed it with the netlify-cli.

Hi @yutamoridev,

I think it’s because you’re using an ancient syntax. When I changed your hello function to this:

exports.handler = async event => {
  console.log('queryStringParameters', event.queryStringParameters)
  return {
    statusCode: 200,
    body: JSON.stringify({ msg: 'Hello, World!' })
  }
}

it works fine.

I’d advise you to change all your functions to this format.

Also, you’re using an ancient version of Netlify CLI. The current version is 6+, while the one in your dependencies is 2. Also, you’re using Netlify Lambda which is no longer required. So, I changed your netlify.toml file to:

[build]
  command = "npm run build"
  functions = "src/lambda"
  publish = "build"

and package.json to:

  "scripts": {
    ...
    "build": "react-scripts build",
    ...
  },
3 Likes

Hi @hrishikesh, thank you so much! I started the project from scratch, following the edits you have suggested and it worked out perfectly. I have been trying to find a solution since yesterday and had no luck. So your help is much appreciated :smile: Have a good day.

1 Like