The documentation for functions since v2 says that there is a Netlify global object, and that this object has an env field for getting environment variables. However, when my function attempts to use the Netlify.env interface I get a reference error:
"ReferenceError: Netlify is not defined"
indicating that the Netlify object is probably absent. Is the documentation incorrect?
I’m certain. I re-engineered existing functions to export default, receive Request objects and return Response objects. If I was on old functions they’d throw an error very quickly (upon using the headers interface). They otherwise work exactly as v2 functions are documented. There’s simply no Netlify global object. I am, however, able to use the Node.js process.env global.
Edit: To be clear, these functions are in production and do the job they’re supposed to do. I rely on global access to environment variables though, so I’m using a wrapper function which attempts to get environment variables from Netlify.env(...), or falls back to process.env[...] (logging whichever worked). The logs from this are how I know there’s still a problem with Netlify.env. You can see that wrapper here (not my finest code, be kind).