我在这里找到的教程上取得了一些进展:
https://www.youtube.com/watch?v=6vcIW0CO07k
但是我被困在了19分钟的时候。
基本上,本教程是使用React和Chatkit构建Instant Messenger应用程序。
我使用以下代码收到一条"Failed to comile“消息,这是一个名为Chatscreen.js的文件:
import React from 'react'
import ChatKit from '@pusher/chatkit'
class ChatScreen extends React.Component {
componentDidMount () {
const chatManager = new Chatkit.ChatManager({
instanceLocator: 'v1:us1:5802c885-ab9d-409b-aa98-5dbcfc69efd1',
userId: this.props.currentUsername,
tokenProvider: new ChatKit.tokenProvider({
url: 'http://localhost:3001/authenticate'
})
})
chatManager
.connect()
.then(currentUser => console.log('currentUser', currentUser))
.catch(error => console.error(error))
}
render() {
return (
<div>
<h1>Chat</h1>
<p>Hello, {this.props.currentUsername}</p>
</div>
)
}
}
export default ChatScreen错误消息为:
Failed to compile.
./src/ChatScreen.js
Line 6: 'Chatkit' is not defined no-undef这是我的github存储库的链接。为什么我会收到这个错误?
发布于 2019-09-26 09:46:28
在我看过他们的文档之后。我想你最好这样导入它。
import { TokenProvider } from "@pusher/chatkit-client-react"我认为问题在于版本不同。你看的VDO是去年的,他们的包装可能有一些变化。
仅供参考:https://pusher.com/docs/chatkit/getting_started/react#adding-a-token-provider-to-your-app
https://stackoverflow.com/questions/58108311
复制相似问题