首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Angular 11/12中使用getstream.io聊天

在Angular 11/12中使用getstream.io聊天
EN

Stack Overflow用户
提问于 2021-10-25 08:04:13
回答 1查看 78关注 0票数 0

我正在尝试使用Angular 11/12的getstream.io。

第1步:通过npm安装getstream安装npm

步骤2:通过npm install express @types/node安装额外的依赖项,并将"types": ["node"]添加到tsconfig

步骤3:初始化StreamChat的简单初始化服务:

代码语言:javascript
复制
import { StreamChat } from "stream-chat";

@Injectable({
  providedIn: 'root'
})
export class ChatService {
  client: StreamChat;

  constructor() {
    this.client = StreamChat.getInstance(environment.getstream.apiKey);
  }

  async connectUserChat() {
    await this.client.connectUser(
      {
        id: 'xxx',
        name: 'Some Testuser'
      },
      "xxx",
    );
  }
}

结果:

代码语言:javascript
复制
Error: node_modules/stream-chat/dist/types/client.d.ts:3:8 - error TS1259: Module '"xxx/node_modules/isomorphic-ws/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

3 import WebSocket from 'isomorphic-ws';
         ~~~~~~~~~

  node_modules/isomorphic-ws/index.d.ts:8:1
    8 export = WebSocket
      ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSynth
eticDefaultImports' flag.


Error: node_modules/stream-chat/dist/types/connection.d.ts:3:8 - error TS1259: Module '"xxx/node_modules/isomorphic-ws/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

3 import WebSocket from 'isomorphic-ws';
         ~~~~~~~~~

  node_modules/isomorphic-ws/index.d.ts:8:1
    8 export = WebSocket
      ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSynth
eticDefaultImports' flag.


Error: node_modules/stream-chat/dist/types/utils.d.ts:2:8 - error TS1259: Module '"xxx-
web/node_modules/stream-chat/node_modules/form-data/index"' can only be default-imported using the 'allowSyntheticDefaul
tImports' flag

2 import FormData from 'form-data';
         ~~~~~~~~

  node_modules/stream-chat/node_modules/form-data/index.d.ts:10:1
    10 export = FormData;
       ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSynth
eticDefaultImports' flag.

你知道怎么解决这个问题吗?

如果getstream lib真的能与Angular一起工作,我也有点困惑。我可以找到一些使用Angular 9的官方教程,但我在他们的文档中找不到任何关于Angular支持的内容。

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2021-10-25 08:41:58

向tsconfig.json添加"esModuleInterop": true暂时删除了错误

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69704618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档