Hi, I have a problem to use Arrow in my JS project...
# arrow
d
Hi, I have a problem to use Arrow in my JS project. I took the versions from the sample project (https://github.com/arrow-kt/Arrow-JS-Template) and I get a compiler error when building. Has anyone experienced this before and has any idea how I can fix it. The sample project can be built and also runs in the browser.
Copy code
> Task :compileDevelopmentExecutableKotlinJs FAILED
e: java.lang.IllegalStateException: Internal error: No flat hash for FUN FAKE_OVERRIDE name:map visibility:public modality:FINAL <B> ($this:arrow.core.Eval<A of arrow.core.Eval.Companion.collapse>, f:kotlin.Function1<A of arrow.core.Eval.Companion.collapse, B of arrow.core.Eval.Companion.collapse.<no name provided>.map>) returnType:arrow.core.Eval<B of arrow.core.Eval.Companion.collapse.<no name provided>.map> [inline,fake_override]
	at org.jetbrains.kotlin.ir.backend.js.ic.InlineFunctionHashBuilder.buildHashes(InlineGraphTracker.kt:157)
	at org.jetbrains.kotlin.ir.backend.js.ic.InvalidationKt.buildCacheForModule(invalidation.kt:184)
	at org.jetbrains.kotlin.ir.backend.js.ic.InvalidationKt.actualizeCacheForModule(invalidation.kt:563)
	at org.jetbrains.kotlin.ir.backend.js.ic.InvalidationKt.actualizeCacheForModule(invalidation.kt:450)
	at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:220)
	at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:178)
	at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:71)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:91)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:43)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1623)
	at jdk.internal.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
s
Hey @Dirk, That is strange. I just checked out the JS-Template and ran
./gradlew build
and
./gradlew browserDevelopmentRun
and both work fine for me. Do you have some custom code that might be causing this? Or run any other commands than I share here that reproduces this error?
d
Oh I'm sorry, I must have been unclear! The example project from Github can be built and executed. However, in my project with various other dependencies (e.g. React-Kotlin wrapper, but also "pure" JS dependencies) the project does not compile. It will probably be a problem with the Kotlin compiler, but I still had the small hope that I have something wrong and a change in build.gradle.kts could fix the problem...
s
Okay, so you don't have extra code yet but only additional dependencies? Could you share your
build.gradle.kts
config?
d
Sorry for the late reply, I was traveling for work. This is an existing project with existing code and additional libraries. Here is the build.gradle.kts:
Copy code
val kotlinWrappersVersion = "0.0.1-pre.332-kotlin-1.6.21"

plugins {
    kotlin("js") version VersionPortalNG.kotlinVersion
    kotlin("plugin.serialization") version VersionPortalNG.kotlinVersion
    id("org.gradlewebtools.minify") version VersionPortalNG.gradleMinify
}

group = "<http://de.xxx.xxx|de.xxx.xxx>"
version = "1.0-SNAPSHOT"

tasks.wrapper {
    gradleVersion = "7.4.2"
}

repositories {
    mavenCentral()
    mavenLocal()
    maven("<https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven>")
    maven {
        url = uri("<https://maven.pkg.jetbrains.space/public/p/ktor/eap>")
        name = "ktor-eap"
    }
    maven(url = "<https://oss.sonatype.org/content/repositories/snapshots/>")
}

kotlin {
    js(IR) {
        binaries.executable()
        browser {
            webpackTask {
                cssSupport.enabled = true
            }

            runTask {
                cssSupport.enabled = true
            }

            testTask {
                useKarma {
                    useChromeHeadless()
                    webpackConfig.cssSupport.enabled = true
                }
            }
        }
    }
    sourceSets {
        dependencies {
            implementation(enforcedPlatform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:$kotlinWrappersVersion"))

            /* React */
            implementation("org.jetbrains.kotlin-wrappers:kotlin-react")
            implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
            implementation("org.jetbrains.kotlin-wrappers:kotlin-react-router-dom")
            implementation((npm("ahooks", "3.3.0")))
            implementation("org.jetbrains.kotlin-wrappers:kotlin-emotion")

            /* DTOs */
            implementation("<http://de.xxx.xxx:shared:1.0-SNAPSHOT|de.xxx.xxx:shared:1.0-SNAPSHOT>") {
                isChanging = true
            }
            implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.0")


            /* Styled */
            implementation(kotlinWrapper("styled"))

            /* Arrow */
            implementation("io.arrow-kt:arrow-core:1.1.2")
            implementation("io.arrow-kt:arrow-optics:1.1.2")
            implementation("io.arrow-kt:arrow-fx-coroutines:1.1.2")
            implementation(kotlin("stdlib-js"))

            /* UI */
            implementation(npm("antd", "4.16.13"))

            /* KTOR */
            implementation(ktorClient("core"))
            implementation(ktorClient("js"))
            implementation(ktorClient("logging"))
            implementation(ktorClient("serialization"))
            implementation(ktorClient("content-negotiation"))
            implementation(ktor("serialization-kotlinx-json"))

            /* Coroutines */
            implementation(kotlinxCoroutines("core"))

            /* Sonstiges */
            implementation(kotlinWrapper("extensions"))
            implementation("io.github.samgarasx:kotlin-moment:2.27.0-pre.12-kotlin-1.5.21")
        }
    }
}

val jsMinify by tasks.creating(org.gradlewebtools.minify.JsMinifyTask::class.java) {
    dependsOn("jsBrowserProductionWebpack")

    srcDir = project.buildDir / "processedResources/jvm/main/files"
    dstDir = project.buildDir / "distributions-minified"

    options {
        compilationLevel = com.google.javascript.jscomp.CompilationLevel.SIMPLE_OPTIMIZATIONS
        env = com.google.javascript.jscomp.CompilerOptions.Environment.BROWSER
    }
}

operator fun File.div(childName: String) = File(this, childName)

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().disableGranularWorkspaces()
}

allprojects {
    tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask> {
        args += "--ignore-scripts"
    }
}