IPFS node not working when used in other files or outside of function scope

Hello everyone, thanks in advance for your time.

I have this electron app where I was previously using js-ipfs but I now I am switching to go-ipfs and ipfsd-ctl.

I manage to connect and the cat function works sometimes and the add function just hangs forever.
Not sure what’s wrong, but this only happens when I export the IPFS node to use it in another file and even in the same file but in a different function.

This worked fine when using ipfs-core, sorry if I am missing something basic I am kind of learning by doing here.

Some code:

import Ctl from "ipfsd-ctl";

//declare the variable in the outer scope
export let ipfsd = null; 

// inside the function that initializes electron
  ipfsd = await Ctl.createController({
        ipfsHttpModule: require("ipfs-http-client"),
        type: "go",
        ipfsBin: ipfsBin,
        ipfsOptions: {
          repo,
        },
        remote: true,
        disposable: false,
        test: false,
        args: ["--migrate", "--enable-gc", "--routing", "dhtclient"],
      });

     await ipfsd.init();
     await ipfsd.start();
    
     // If I were to do ipfsd.api.add(someContent) inside this function it would work fine.

// outside the function/ imported in a different file
const fileHash = await ipfsd.api.add({
      content: fileContent,
    });

// it doesn't work

Is there a special way to export the ipfsd node that I am missing?