如何向 kotlin 添加新的 npm 依赖?

问题描述 投票:0回答:1

在浏览 Kotlin/js tutorial 时,我尝试用

react-youtube-lite
替换已弃用的
react-youtube
库,但在浏览器控制台中出现错误:

警告:React.createElement:类型无效——需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:未定义。您可能忘记从定义它的文件中导出组件,或者您可能混淆了默认导入和命名导入。

我更新了

build.gradle.kts

dependencies {
...
    //Video Player (chapter 7)
    implementation(npm("react-youtube-lite", "1.5.0"))
    implementation(npm("react-youtube", "9.0.3"))
...
}

我看到yarn.lock已在browserRun任务上成功更新,新的

react-youtube
就在那里。

我创建了新组件,但使用它会出现上述错误:

@file:JsModule("react-youtube")
@file:JsNonModule

import react.*

@JsName("ReactYoutube")
external val ReactYoutube: ComponentClass<ReactYoutubeProps>

external interface ReactYoutubeProps : Props {
    var videoId: String?
    var opts: Any
}

示例: https://github.com/beshur/kotlin-confexplorer/pull/1

reactjs kotlin
1个回答
0
投票

好的,正如我的一位朋友所建议的,我需要使用

@JsName("default")
来使用
react-youtube
包中的默认导出。

© www.soinside.com 2019 - 2024. All rights reserved.