2

Created a Kotlin MPP for developing a JS library, and a JVM lib. Everything worked well in the Kotlin world and I was able to build the project. Once build was completed the distributions folder(inside build) had the projectName.js file and projectName.js.map file.

I created an HTML using this js and tried opening in a browser and its throwing the following error.

The HTML:

<html lang="en"><head>
    <meta charset="UTF-8">
    <title>Hello, Kotlin/JS!</title>
</head>
<body>
<script src="projectName.js"></script>
</body></html>

The error:

Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
    at Object.i (projectName.js:10)
    at Object.<anonymous> (projectName.js:10)
    at n (bootstrap:19)
    at Object.<anonymous> (projectName.js:10)
    at n (bootstrap:19)
    at Object.<anonymous> (projectName.js:10)
    at n (bootstrap:19)
    at bootstrap:83
    at projectName.js:1
    at universalModuleDefinition:9

My distributions folder just has the 2 files mentioned above. Can someone help me understand what is wrong? Are there any other js files that I should add to my HTML ? Or anything more that I should do?

Adding build.gradle

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
    id 'org.jetbrains.kotlin.multiplatform'
    id 'com.android.library'
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.20'
}

kotlin {
    android()
    js {
        browser()
        binaries.executable()
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation "io.ktor:ktor-client-core:$ktor_version"
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version"
                implementation "com.ionspin.kotlin:bignum:0.3.1"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        androidMain {
            dependencies {
                implementation 'com.google.android.material:material:1.2.1'
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_coroutines_version"
                implementation "io.ktor:ktor-client-android:$ktor_version"
            }
        }
        androidTest {
            dependsOn(androidAndroidTestRelease)
            dependencies {
                implementation kotlin('test-junit')
                implementation 'junit:junit:4.13'
            }
        }
        jsMain {
            dependencies {
                implementation "io.ktor:ktor-client-js:$ktor_version"
            }
        }
    }
}

android {
    compileSdkVersion android_compile_sdk_version as Integer
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion android_min_sdk_version as Integer
        targetSdkVersion android_target_sdk_version as Integer
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    packagingOptions {
        exclude 'META-INF/*.kotlin_module'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

Please help !

4
  • Feel free to ask if you need any more information on the same. Commented Sep 16, 2021 at 10:24
  • 1
    Could you add your build.grade configuration? Commented Sep 16, 2021 at 11:14
  • Added build.gradle Commented Sep 16, 2021 at 11:40
  • @tmarwen anything u can add would be helpful :) Commented Sep 17, 2021 at 5:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.