How to use Node native Fetch in Netlify Functions

22nd Nov 2022

Answer 👌

In your Netlify projects environment variable settings set this:

Value: nodejs18.x

Explaination 🤔

Netlify Functions are built on AWS Lambda. Netlify allows us to provide a AWS_LAMBDA_JS_RUNTIME Env Var that sets the runtime for the function on AWS.

Native Fetch in Node is only available in Node 18 and above. I guess the default node version used is not Node 18.

Further reading:Lambda runtime optionsNode 18 announcementNetlify docs