2

I'm developing an application with Kotlin/JS and Gradle. I can easily add npm dependencies from the default npm registry with the implementation npm("query-string", "7.0.0") command.

However, I cannot add an npm dependency from a different npm registry like Github Packages. I want to add this npm dependency to my project. Without gradle I could just install the dependency by just using the command line and npm install @gitliveapp/firebase-firestore but this doesn't work with the gradle npm command. I also tried implementation npm("@gitliveapp/firebase-firestore", "0.5.4") but this produces the following error: Couldn't find package "@gitliveapp/[email protected]" required by "project" on the "npm" registry..

How can I add npm dependencies with gradle from different registries other than the npm public registry.

build.gradle

plugins {
    id 'org.jetbrains.kotlin.js' version '1.5.10'
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.0'
}

repositories {
    mavenCentral()
    maven { url 'https://maven.pkg.jetbrains.space/public/p/kotlin/p/kotlin/kotlin-js-wrappers' }
}

dependencies {
    testImplementation 'org.jetbrains.kotlin:kotlin-test-js'
    implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react', version: '17.0.2-pre.212-kotlin-1.5.10'
    implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react-dom', version: '17.0.2-pre.212-kotlin-1.5.10'
    implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-styled', version: '5.3.0-pre.212-kotlin-1.5.10'
    implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react-router-dom', version: '5.2.0-pre.212-kotlin-1.5.10'
    implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-css', version: '1.0.0-pre.212-kotlin-1.5.10'
    implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-redux', version: '4.0.5-pre.212-kotlin-1.5.10'
    implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react-redux', version: '7.2.3-pre.212-kotlin-1.5.10'
    implementation 'dev.gitlive:firebase-firestore:1.3.1'
    implementation 'dev.gitlive:firebase-auth:1.3.1'
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
    implementation 'org.kodein.di:kodein-di-js:7.6.0'
    implementation npm("query-string", "7.0.0")
    implementation npm("firebase", "8.6.8")
    implementation npm("@gitliveapp/firebase-firestore", "0.5.4")

}

kotlin {
    js(LEGACY) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
        }
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile).all {
    kotlinOptions {
        freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
    }
}
2
  • Please provide a sample build.gradle or build.gradle.kts Commented Jun 22, 2021 at 0:46
  • @FranciscoMateo I have updated my question Commented Jun 22, 2021 at 21:24

1 Answer 1

2

Unfortunately, you can't do it via gradle now, see an issue. But you can create file .npmrc (or .yarnrc) in the project root and configure here (https://docs.npmjs.com/configuring-npm/npmrc.html)

Additionally see the documentation:

For example, to use a custom registry for npm packages, add the following line to a file called .yarnrc in the project root: registry "http://my.registry/api/npm/"

Sign up to request clarification or add additional context in comments.

Comments

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.