serverless-plugin-typescript icon indicating copy to clipboard operation
serverless-plugin-typescript copied to clipboard

When using promises (async await), nothing is returned

Open rafaelcorreiapoli opened this issue 7 years ago • 1 comments

Hello! I've set up the project correctly. When I invoke locally the following code

const fetchSomething = () => new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve({
      some: 'thing',
    })
  }, 1000)
})

export const asyncTest = async (event: APIGatewayEvent) => {
  const x = await fetchSomething()
  return {
    statusCode: 200,
    body: JSON.stringify(x),
  }
}

Nothing is returned.

I've tested using callbacks in this same project and it works as expected

rafaelcorreiapoli avatar Feb 19 '18 23:02 rafaelcorreiapoli

You need to make sure that your serverless project is using node8.10 as its runtime ... async won't work before that.

DanielSchaffer avatar May 03 '18 20:05 DanielSchaffer