找不到模块:错误:无法在Kotlin/JS中解析'firebase/app'

pgky5nke  于 2022-11-25  发布在  Kotlin
关注(0)|答案(1)|浏览(86)

在Kotlin/JS项目中,我添加了Firebase依赖项-

implementation(npm("firebase", "9.14.0"))

添加了外部声明文件:

@file:JsModule("firebase/app")
@file:JsNonModule
@file:Suppress(
    "INTERFACE_WITH_SUPERCLASS",
    "OVERRIDING_FINAL_MEMBER",
    "RETURN_TYPE_MISMATCH_ON_OVERRIDE",
    "CONFLICTING_OVERLOADS"
)
package externals

import kotlin.js.Promise

external fun deleteApp(app: FirebaseApp): Promise<Unit>

external interface FirebaseApp {
    var name: String
    var options: FirebaseOptions
    var automaticDataCollectionEnabled: Boolean
}

external interface FirebaseAppSettings {
    var name: String?
        get() = definedExternally
        set(value) = definedExternally
    var automaticDataCollectionEnabled: Boolean?
        get() = definedExternally
        set(value) = definedExternally
    var setting: String
}

external interface FirebaseOptions {
    var apiKey: String?
        get() = definedExternally
        set(value) = definedExternally
    var authDomain: String?
        get() = definedExternally
        set(value) = definedExternally
    var databaseURL: String?
        get() = definedExternally
        set(value) = definedExternally
    var projectId: String?
        get() = definedExternally
        set(value) = definedExternally
    var storageBucket: String?
        get() = definedExternally
        set(value) = definedExternally
    var messagingSenderId: String?
        get() = definedExternally
        set(value) = definedExternally
    var appId: String?
        get() = definedExternally
        set(value) = definedExternally
    var measurementId: String?
        get() = definedExternally
        set(value) = definedExternally
}

external fun getApp(name: String = definedExternally): FirebaseApp

external fun getApps(): Array<FirebaseApp>

external fun initializeApp(options: FirebaseOptions, name: String = definedExternally): FirebaseApp

external fun initializeApp(options: FirebaseOptions): FirebaseApp

external fun initializeApp(options: FirebaseOptions, config: FirebaseAppSettings = definedExternally): FirebaseApp

external fun initializeApp(): FirebaseApp

external fun registerVersion(libraryKeyOrName: String, version: String, variant: String = definedExternally)

external val SDK_VERSION: String

external fun setLogLevel(logLevel: String /* "debug" | "verbose" | "info" | "warn" | "error" | "silent" */)

接下来,我调用了initializeApp函数来初始化firebase。

val options: dynamic = object {}
val config: dynamic = object {}
options["appId"] = "xxx"
options["apiKey"] = "xxx"
initializeApp(options.unsafeCast<FirebaseOptions>())

之后,我得到这个错误-模块未找到:错误:无法解析'firebase/app'
需要帮助,这和提前感谢.

imzjd6km

imzjd6km1#

将Firebase NPM库版本降级为9.13.0后,问题解决

implementation(npm("firebase", "9.13.0"))

相关问题