You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装eventsource相关依赖后仍报‘EventSource is not a constructor’的问题求助

安装eventsource相关依赖后仍报‘EventSource is not a constructor’的问题求助

大家好,我最近在Ubuntu环境里折腾EventSource的时候碰到个棘手的问题,想请教下各位大佬!

我已经通过下面这两个命令安装了相关依赖:

  • npm install launchdarkly-eventsource
  • npm install eventsource

但当我运行这段代码的时候,却一直报错 "EventSource is not a constructor":

var EventSource = require('eventsource');
var es = new EventSource('http://ac1.mqtt.sx3ac.com/api/gap/nodes?filter_mac=DC:0D:30:00:07:25&filter_rssi=-75&mac=CC:1B:E0:E2:52:D4&active=1&event=1&chip=1&access_token=d9010bc1377a41ac56f9096246978417ceb4dc7f6d44e5e4dd51658ce9c74a66');
checkTime();
var startTime = new Date().getTime();

es.onmessage = function(e) {
    var endTime=new Date().getTime();
    console.log(e.data);
};

es.onerror = function(e) {
    console.log('ERROR!'+e.status);
    es.close();
    return;
};

function checkTime() {
    setTimeout(function() {
        es.close();
        return;
    }, 60000);
}

我已经试过重新安装这些依赖包了,但问题还是没解决,有没有朋友能帮我看看这到底是哪里出问题了呀?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 10:03:03