Hi, I’m trying to get kotlin-react to work for the...
# javascript
m
Hi, I’m trying to get kotlin-react to work for the first time. I tried building my project with Maven, but I’m getting some “module is not defined” errors when I run it in the browser. After some searching, I think it’s because I need the “core-js” dependency from NPM. Now my problem is, I can’t find any way to include NPM-dependencies through Maven. Do anyone know if you can include those with Maven only (without a package.json and doing “npm install”? It think this is the equivalent in Gradle:
Copy code
kotlinFrontend {
    npm {
        dependency "core-js"
    }
}
r
You can use the npm implementation wrapper in your sourcesets dependencies, like this
Copy code
kotlin {
    sourceSets {
        val jsMain by getting {
            dependencies {
                implementation(npm("monk", "7.1.1"))
            }
        }
    }
}
(that’s using the kotlin dsl, but it should be pretty similar in groovy)
Wow, I totally failed to keep the ‘Maven’ context in my head for your question. Sorry about that. I’m sick today.
m
Hehe, thanks anyway 🙂 I decided to give Gradle a try, but I’m having even more problems there. Can’t even get the basic “document.write(“Hello world!“)” to show up in my browser.
Your snippet is just giving me this:
Copy code
KotlinSourceSet with name 'jsMain' not found.
r
I assume that you haven’t applied the kotlin js plugin then
m
I’ve been searching all over internet for a simple up-to-date example for this, but I can’t seem to find any.
r
one sec, there’s a link for that
m
I’ve got this at the top:
Copy code
plugins {
    kotlin("js") version "1.3.61"
}
Ah, thanks. Not sure if I’ve seen that one yet 😛
r
you’re probably missing the js config section inside of kotlin {}
m
I got it running at last. Thanks for the help. 🙂
👍 1