@elastic/elasticsearch npm library not working in mongodb realm function

I am trying to integrate @elastic/elasticsearch npm library in mongodb realm function. To achieve that I addded @elastic/elasticsearch as dependency.

exports = async function(arg){
const { Client } = require('@elastic/elasticsearch');
  try {
    const apiKey = context.values.get("ES_API_KEY");
    const cloudId = context.values.get("ES_CLOUD_ID");
    const client = new Client({
    cloud: {
        id: cloudID
    },
    auth: {
        apiKey
    }
})
   return client;
   
  } catch(err) {
    console.log("Error occurred while executing:", err.message);
    return { error: err.message };
  }

When I did so I get below error.

failed to execute source for 'node_modules/@elastic/elasticsearch/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/lib/connection/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/lib/connection/UndiciConnection.js': FunctionError: failed to execute source for 'node_modules/undici/index.js': FunctionError: failed to execute source for 'node_modules/undici/lib/api/index.js': FunctionError: failed to execute source for 'node_modules/undici/lib/api/api-request.js': FunctionError: Cannot find module 'async_hooks'

what is causing this issue?

It seems at this point of time mongodb functions does not support latest @elastic/elasticsearch version 8.

Downgrading version to 7.17.0 resolved this issue.