Fetch is not defined on production

I am working on a project using the ShopifyStorefrontApi as well as the shopify-buy npm package.

Netlify functions work flawlessly on the localhost, but once everything is deployed I am getting a reference error that fetch is not defined. When the create-cart function gets executed, which is on first page load, I store the data in localStorage. But instead i can see what error it returns in the localStorage:

{"errorType":"ReferenceError","errorMessage":"fetch is not defined","trace":["ReferenceError: fetch is not defined","    
at Client3.fetcher (/var/task/netlify/functions/create-cart.js:1163:9)","    at Client3.send (/var/task/netlify/functions/create-cart.js:1260:23)","    
at CheckoutResource2.create (/var/task/netlify/functions/create-cart.js:7897:37)","    at Runtime.handler (/var/task/netlify/functions/create-cart.js:8899:45)","   
at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1089:29)"]}

I think that it might have to do something with the node version, once I updated to node18 everything broke big time. Then I managed to revert to node16 and refactor the api calls using axios instead of fetch. Been struggling on this for many hours, help would be appreciated.

The node version I am on is 16.19.0, @types/node is = to the node version.
NODE_VERSION env is set to 16.19.0 in the netlify ui.
I will attach images of the shopify client and of the way i am making the api calls.
I can give some more context about the 3th screenshot if needed.


(restricted to upload only one image so I will do it this way)

Set AWS_LAMBDA_JS_RUNTIME environment variable in the UI with the value nodejs18.x.

Still getting the same error. Should I delete the NODE_VERSION env in the ui? And should I keep using node16, or update back to 18?

Please share the site name.

Oh yeah sorry I forgot:

Did you re-deploy after setting the above variable?

Yes, I just did again. Still same error.

I will try deleting the NODE_VERSION env, because it was set to 14. Could be because of that, or maybe setting it to 18, no clue at this point

Okay, now I am getting the correct data into the localStorage. Thank you so much, adding the env you told me and setting NODE_VERSION env to 18 fixed it.