Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined #9

Open
abtx opened this issue Aug 7, 2019 · 5 comments

Comments

@abtx
Copy link

abtx commented Aug 7, 2019

Hi, thanks for this great little example, it helped me get started quickly and get better understanding of how to use Netlify's implementation of Lambda.

Something I wanted to share as well is I've set up the secret in .env and added export $(cat .env | xargs) && to the start script which is handy for local dev.

As to the error - I find that if you unwrap your lambda functions return responses from the callback objects the error is fixed:
console.log('error', error) return { statusCode: 200, body: JSON.stringify(ret) }

I thought sharing this might help someone bootstrap this project. Thanks!

@kluplau
Copy link

kluplau commented Sep 11, 2019

Instead of running npm run start, try using netlify dev. It's Netlify's CLI that runs the functions as they are run when pushed to production.

@JeffML
Copy link

JeffML commented Sep 11, 2019

netlify dev gives me a different error when loading the page.

Request from ::1: GET /.netlify/functions/todos-read-all
Function `todo-read-all` invoked
(node:6925) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Todo refs [
  Ref(Collection("todos"), "243239304743092745"),
  Ref(Collection("todos"), "243239497348678153"),
  Ref(Collection("todos"), "243241612879069710")
]
3 todos found
Response with status 200 in 418 ms.
◈ Error during invocation:  lambda response was undefined. check your function code again.
/usr/local/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
◈ Error during invocation:  lambda response was undefined. check your function code again.
/usr/local/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end

@JeffML
Copy link

JeffML commented Sep 11, 2019

It has all the symptoms of a callback being called twice, once with the correct parameters, and the second with no parameters. Not able to track it down, though.

@franva
Copy link

franva commented Aug 8, 2020

It has all the symptoms of a callback being called twice, once with the correct parameters, and the second with no parameters. Not able to track it down, though.

I am facing the same issue. How did you solve it?

@JeffML
Copy link

JeffML commented Aug 8, 2020

@franva it was nearly a year ago, so I can't remember the specifics, but I believe I had my netlify lambda folder set up wrong, or was skipping a step. I wrote up what I did to finally get it working here: https://www.freecodecamp.org/news/netlify-functions-firebase-and-graphql-working-together-at-last/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants