Does kotlin download/use its own version of node, ...
# javascript
d
Does kotlin download/use its own version of node, and if so, is it possible to change that version? I have an npm dependency that requires
node >= 12.17
and my build is failing since it seems to be running with
12.16.1
. I use nvm on my computer for other node projects, and the only versions I have installed are
8.16.2
,
10.20.1
,
12.18.3
(default), and
14.8.0
so I have no idea where where
12.16.1
is coming from
v
Do you use Groovy DSL or Kotlin DSL for your build scripts?
Groovy DSL:
Copy code
kotlinNodeJs {
    nodeVersion = '12.18.3'
}
Kotlin DSL:
Copy code
configure<NodeJsRootExtension> {
    nodeVersion = "12.18.3"
}
12.16.1 indeed is the default version used
1
d
Thanks! Can you change the node version when targeting the browser as well? I'm getting this error:
Copy code
Extension of type 'NodeJsRootExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, KotlinJsProjectExtension, KotlinTestsRegistry, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaPluginExtension, JavaInstallationRegistry, JavaToolchainService]
v
No idea, I just used Kotlin/JS to build a GitHub action
Hm, are you suer you are doing in the correct project or something similar? From a quick look at the code and a quick test in changing the sub-target to
browser
it seems the same extension is present and can be configured.
d
I think so, I put it right beside my kotlin js browser config - does it need to go somewhere else?
Copy code
kotlin.js {
    browser {
        // See <https://kotlinlang.org/docs/reference/javascript-dce.html#known-issue-dce-and-ktor>
        dceTask {
            keep("ktor-ktor-io.\$\$importsForInline\$\$.<http://ktor-ktor-io.io.ktor.utils.io|ktor-ktor-io.io.ktor.utils.io>")
        }
    }

    binaries.executable()
}

configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
    nodeVersion = "12.18.3"
}
v
No, should be fine I think
d
Oh configuring it on
rootProject
instead worked! Thanks for the help 🙂
v
Yes, this extension will always only be added to the root project
👍 1
Copy code
check(project == project.rootProject) {
    "NodeJsRootPlugin can be applied only to root project"
}
d
Gotcha, thanks
v
next line adds the extension