在 Angular5 中使用 SockJS 时出错 - "sockjs_client_1.SockJS is not a constructor"

Error using SockJS in Angular5 - "sockjs_client_1.SockJS is not a constructor"

我现在正在关注这个 tutorial,我已经到了必须在我的 Angular5 组件中实例化我的 SockJS-Client 的地步。

以下是我所做的:

  1. 我执行了以下命令来安装所需的库:

    npm install stompjs
    npm install sockjs-client
    npm install jquery
    
  2. 我像这样将库导入到我的组件中:

    import { Stomp } from 'stompjs';
    import { SockJS } from 'sockjs-client';
    import $ from 'jquery';
    
  3. 最后我尝试实例化 SockJS:

    constructor(){
        this.initializeWebSocketConnection();
    }
    
    initializeWebSocketConnection(){
        let ws = new SockJS(this.serverUrl);  //<- This is the line causing the error
        this.stompClient = Stomp.over(ws);
        let that = this;
        this.stompClient.connect({}, function(frame) {
            that.stompClient.subscribe("/chat", (message) => {
                if(message.body) {
                    $(".chat").append("<div class='message'>"+message.body+"</div>")
                    console.log(message.body);
                }
            });
        });
    }
    

我得到的错误是:

ERROR Error: Uncaught (in promise): TypeError: sockjs_client_1.SockJS is not a constructor

我找不到关于这个问题的任何信息。

试试看:

import * as SockJS from 'sockjs-client';

import SockJS from 'sockjs-client';