How to mount a .dmg file with JXA?
One wouldn't use DiskImageMounter to do this because, despite it giving the illusion that it's scriptable and loaded with commands in its AppleScript dictionary, it never returns a valid reference to any image that it opens; therefore AppleScript never gets informed it's done the job; and  DiskImageMounter sacks it off, quits, and invalidates the connection with AppleScript thus throwing an error.  And it does this every.  Single.  Time.  So, it is reliably balls.

The way to mount a disk image with AppleScript is to use an application I very rarely endorse using but for very few specific tasks, which is Finder.  DiskImageMounter is the only application less reliable than Finder, but Finder is a trier, and it does succeed with mounting volumes without causing too much of a stink:

set f to POSIX file "/path/to/diskimage.dmg" as alias
tell application id "com.apple.Finder" to open f


It, too, doesn't return a reference to the mounted volume, but you can get Finder to enumerate the disks already mounted beforehand, then enumerate them again afterwards, and the new one that appears will be your mounted volume:

set f to POSIX file "/path/to/diskImage.dmg" as alias
tell application id "com.apple.Finder"
    set ejectables to disks

    open f

    repeat until disks ≠ ejectables
        delay 1
    end repeat

    return the POSIX path of last item of (disks as alias list)
end tell




Finally...  The JXA:

Finder=Application('com.apple.Finder');
f=Path('/path/to/diskImage.dmg');
Finder.open(f);