After trying many different things, i still do not know the exact reason this is happening. However, i made some changes to my code and the problem disappeared.
There was a class in my code which was importing many other classes which in turn used many 3rd party service packages. It was implementing a factory pattern to create clients for each service. Moving the import statements from the top level into the code solved the problem.
for eg:
I had:
import {LocalFileSystemManager} from "~~/server/lib/LocalFileSystemManager"
I replaced it with a function:
async filestore(path: string): FileSystemManager
{
const runtime_config = useRuntimeConfig();
const {LocalFileSystemManager}: typeof import("~~/server/lib/LocalFileSystemManager") = await import("~~/server/lib/LocalFileSystemManager");
return new LocalFileSystemManager(path, this);
}