Is it possible to import a UMD module into a kotli...
# webassembly
b
Is it possible to import a UMD module into a kotlin wasm code base and define kotlin interop classes/objects for that module?
For example, I am trying to implement the below js via kotlin interop
Copy code
mapboxgl.accessToken = "my-access-token"
I've tried a bunch of different variations of the below
Copy code
@file:JsModule("mapbox-gl")
package com.basebeta.map

external object mapboxgl : JsAny {
   var accessToken: String
}
but each one results in a runtime uncaught WebAssembly.Exception
Ah! Only ES modules are supported per the documentation table here
Copy code
Supports ES modules only. There is no analog of the @JsNonModule annotation. Provides its exports as properties on the default object. Allows exporting package-level functions only.
e
you don't need
@JsNonModule
, I haven't used mapbox but I'd expect
Copy code
@JsModule("mapbox-gl")
external var accessToken: JsString
as the docs make it look like a direct export
b
will give that a try, but I am wondering if the compiler will be thrown off by the function at the top of the UMD module
ok, I haven't gotten to your suggestion, but found an alternate means of gettings things working. I've included the script tags for mapbox in my
index.html
and then defined the below for interop
Copy code
external object mapboxgl {
   var accessToken: JsString
}
Was able to execute
Copy code
mapboxgl.accessToken = "my-access-token".toJsString()
and confirm that the token was populated correctly with
console.log(mapboxgl.accessToken)
in chrome debugger