我在此处找到的教程上取得了一些进展:
https://www.youtube.com/watch?v=6vcIW0CO07k
但我被困在 19 分钟左右。
基本上,本教程是使用 React 和 Chatkit 构建 Instant Messenger 应用程序。
我使用以下代码收到“无法编译”消息,该代码是一个名为 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 存储库的链接。为什么我会收到此错误?