Koltin multiplatform Javascript IR build creates empty module



I have added the JS target for our Kotlin Multi platform project. The project is named STT.

  js(IR) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
            webpackTask {
                output.libraryTarget = "umd"
            }
        }
    }

When I look at the build folder or when I run the JS task jsRun the JS lib looks empty.

Here is for example the stt.js from the build folder

(function (root, factory) {
  if (typeof define === 'function' && define.amd)
    define(['exports'], factory);
  else if (typeof exports === 'object')
    factory(module.exports);
  else
    root.stt = factory(typeof sttalg === 'undefined' ? {} : stt);
}(this, function (_) {
  'use strict';
  return _;
}));


That essentially is an empty object

However, when I use the BOTH or Legacy that file looks ok

js(LEGACY) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
            webpackTask {
                output.libraryTarget = "umd"
            }
        }
    }

What am I missing ?

Answer

The IR backend doesn’t export any code to js by default. You need to add @JsExport to the declarations you want accessible. See https://kotlinlang.org/docs/js-to-kotlin-interop.html#jsexport-annotation



Source: stackoverflow