Hey all, does anyone have more context on this err...
# javascript
n
Hey all, does anyone have more context on this error? Couldn't find anything by googling: "Dependency to project with multiple js/wasm compilations is not supported yet" The error is clear enough. I have a module in my project that declares two js targets (with a gradle attribute to distinguish them), and another module with those two same js projects that I want to depend on the other module. I know this is a bit of an unusual use-case, but basically we have two separate products that are both JS, but we need different actual implementations for both (and both are browser targets as well). Any potential work-arounds, and any clue when this will be supported in the future?
t
Do you need 2 JS libraries or 2 JS applications?
but we need different actual implementations for both
How "tumbler" looks?
e
that declares two js targets
This is currently unsupported, and only works because Kotlin devs have been nice enough to keep it explicitly for K/JS, until a separation between Node.js and browser is figured out. Did you configure the two targets like this?
n
No, both are browser targets.
And it's technically two different plugin APIs I want to target with the same Kotlin expect API. Ideally I'd want both a library (for the API abstraction I'm building), as well as the application using that library to be able to target either API.
t
Small example/description will be helpful
Like: 1. I have
A
,
B
,
C
2.
A
,
B
should be exported in lib
aaa
3.
B
,
C
should be exported in lib
bbb
n
Example:
Copy code
kotlin {
    js("foo") {
        browser()
    }

    js("bar") {
        browser()
    }
}
Copy code
// commonMain/kotlin/SomeApi.kt

expect fun something()

// fooMain/kotlin/SomeApi.foo.kt

actual fun something() = ...

// barMain/kotlin/SomeApi.bar.kt

actual fun something () ...
Obviously my real example is a lot more complex than this, and also with expect / actual classes. But the idea is I want something depending only on the
commonMain
expect API to be able to be compiled to an implementation using
foo
or
bar
, without any dynamic dispatch.
Since I have expect / actual classes, I can't use standard polymorphism.
t
If you use bundler - you can use env flags instead.
Copy code
actual fun something () {
    if (import.meta.env.FOO) {
        somethingFoo()
    } else {
        somethingBar()
    }
}
Bundler will remove redundant/dead code automatically
n
Ahh, yeah. fair enough. That's a good workaround for sure.
I just feel like it'd be nice to be able to have support for multiple targets per-platform in general. KMP to me seems kind of like a module system for Kotlin, but specialized to the case of targeting multiple platforms, and sometimes I wish it was more general than that. The ability to get compiler feedback if (e.x.) a certain platform has a missing implementation is a killer feature to me.
t
Which part is platform specific in your case?