npm

abstract fun npm(name: String, version: String): Dependency

Declares a dependency on the NPM module.

Calling npm automatically adds the dependency to the enclosing dependency collector:

kotlin.sourceSets["jsMain"].dependencies {
npm("is-odd-even", "^1.0.0")
}

NPM dependencies should not be applied to Gradle dependency scopes such as api, implementation, and so on. Passing the returned dependency to them, as in implementation(npm("is-odd-even", "^1.0.0")), is deprecated - the returned value is only kept for backward compatibility.

The version will be parsed by node-semver. See the node-semver README for the supported syntax.

Creating NPM dependencies is only relevant for Kotlin entities that target JS or WasmJS.

Return

The declared NPM dependency, kept for backward compatibility; it must not be passed to a Gradle dependency scope.

Parameters

name

The NPM dependency name

version

The NPM dependency version


abstract fun npm(name: String, version: Provider<String>)

Declares a dependency on the NPM module.

Calling npm automatically adds the dependency to the enclosing dependency collector.

version is resolved lazily, so it may be provided by a value that is not yet known when the declaration is made:

kotlin.sourceSets["jsMain"].dependencies {
npm(
"is-odd-even",
project.providers.gradleProperty("isOddEvenVersion"),
)
}

If version has no value, then the build fails when the declaration is used.

The version will be parsed by node-semver. See the node-semver README for the supported syntax.

Creating NPM dependencies is only relevant for Kotlin entities that target JS or WasmJS.

Parameters

name

The NPM dependency name

version

The provider of the NPM dependency version


abstract fun npm(name: String, directory: File): Dependency

Declares a dependency on the NPM module located in a local directory.

Calling npm automatically adds the dependency to the enclosing dependency collector:

kotlin.sourceSets["jsMain"].dependencies {
npm("is-odd-even", project.file("npm/is-odd-even"))
}

NPM dependencies should not be applied to Gradle dependency scopes such as api, implementation, and so on. Passing the returned dependency to them, as in implementation(npm("is-odd-even", project.file("npm/is-odd-even"))), is deprecated - the returned value is only kept for backward compatibility.

Creating NPM dependencies is only relevant for Kotlin entities that target JS or WasmJS.

Return

The declared NPM dependency, kept for backward compatibility; it must not be passed to a Gradle dependency scope.

Parameters

name

The NPM dependency name.

directory

The directory where dependency files are located (See NPM directory keyword)


abstract fun npm(directory: File): Dependency

Deprecated

Deriving the NPM dependency name from the directory is deprecated, declare the name explicitly

Replace with

npm("dependency-name", directory)

Deprecated - deriving the NPM dependency name from the directory is deprecated. Declare the name explicitly instead:

kotlin.sourceSets["jsMain"].dependencies {
npm("is-odd-even", project.file("npm/is-odd-even"))
}

Scheduled for removal in Kotlin 2.7.

Return

The declared NPM dependency, kept for backward compatibility; it must not be passed to a Gradle dependency scope.

Parameters

directory

The directory where dependency files are located (See NPM directory keyword)