Async/await lambda function example

hi folks! the example works fine - IF you use netlify-lambda! that’s why it’s in the netlify-lambda repo. If you are NOT using netlify-lambda, and use the export syntax, you will get this exact error. If you want more function examples without netlify-lambda you can check the docs, or Functions examples - Netlify Functions or https://functions-playground.netlify.com/

One of the reasons netlify-lambda exists is because Node.js does not yet have ES modules support. ES modules syntax is the import and export syntax that you see me writing in there (note that this is different from the valid exports.functionName syntax above - confusing, i know). One of the express purposes of netlify-lambda is to allow people to write ES modules syntax, because it uses webpack underneath with a node target - hence copying an example directly from its readme without using the tool won’t work in “raw Node”.

Hope that makes sense and i’ll modify the readme to make clear.

2 Likes