'Cannot read properties of undefined (reading 'loadCurrentSession')

I use shopify api, why I get this error message:

Cannot read properties of undefined (reading 'loadCurrentSession')
 const Shopify =  require('@shopify/shopify-api');

 const { Product } = require('@shopify/shopify-api/dist/rest-resources/2022-04/index.js');


// Initializing a client to return content in the store's primary language

  const test_session = await Shopify.Utils.loadCurrentSession(request, response);
  const d = await Product.all({
    session: test_session
  })


Solution 1:[1]

First Define this function in your root server.js file

 export default async function returnSessionData(req, res) {
  const decode =  await Shopify.Utils?.loadCurrentSession(req, res);
  return decode
}

And Call this returnSessionData(req, res) from your route-controller

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashik Rana