`@JsExport object` with ES-modules

I’m in the process of trying to switch to ES-modules for a common library that is used by my Angular application.

package com.mydomain.myproj.common
object GlobalConstants {
    const val VERSION = "0.64.0"

I previously accessed such transpiled code like this:

import * as myproj_top from "myproj";
import myproj_common =  myproj_top.com.mydomain.myproj.common;
import GlobalConstants = myproj_common.GlobalConstants;

Ugly, but it works, and I could use it in my code like GlobalConstants.VERSION to get the value.

With useEsModules(), I don’t have to go through all those import hoops. This works as expected:

import { GlobalConstants } from "myproj";

However, I cannot use that imported object the same way. Instead of GlobalConstants.VERSION, it seems I need to write GlobalConstants.getInstance().VERSION.

Is this expected or am I just missing something obvious?

1 Like