Using MPP library in Kotlin/JS browser app with JS dependency

I am following the “Create and publish a multi-platform library” tutorial (Create and publish a multiplatform library – tutorial | Kotlin). It creates a Base64 encoder with JVM and JS implementations. I’ve tried including that library in a full-stack MPP application. The library is accessible from the Kotlin/JVM back-end as well as the Kotlin/JS front-end in the browser. BUT, the dependency on the “Buffer” npm function does not work in the browser. Specifically, I see this error:

Uncaught ReferenceError: Buffer is not defined

If I comment out the code that references the Buffer object in the JS implementation and simply return a constant from that function, that works. So I know I’m getting the library included in my full-stack application correctly. It just can’t access the Buffer object.

So then I tried adding a dependency on the browser-implementation of Buffer (buffer - npm) both in the library and in the application. There was no effect on the error.

    val jsMain by getting {
        dependencies {
            implementation(npm("buffer", "6.0.3"))

Any suggestions?

I’ve seen this once and changed the dependency from “implementation” to “api” that solved the issue.

Didn’t help in this case :slightly_frowning_face: . Thanks, though.