问题
我想使用Socket。IO与我的Angular应用程序。我和巴泽尔一起构建并运行这个应用程序。
但是,在运行开发服务器时,浏览器控制台中出现错误。请注意,运行prod服务器运行良好。
我认为错误是由node_modules/engine.io-client/lib/transport.js
第95行引起的。
onData(data) {
const packet = parser.decodePacket(data, this.socket.binaryType);
this.onPacket(packet);
}
这很可能是因为从engine.io-parser
导入的parser
不使用浏览器库。因此,我们可能需要对其进行修补,使其使用浏览器库。
控制台中的实际错误为:
ERROR TypeError: decodePacket is not a function
at Object.decodePayload (ts_scripts.js?v=89114305:17072)
at XHR.onData (ts_scripts.js?v=89114305:15937)
at Request.<anonymous> (ts_scripts.js?v=89114305:15559)
at Request.Emitter.emit (ts_scripts.js?v=89114305:14385)
最小复制
你可以在这里自己试试:flolu/angular-bazel-socketio3-issue
开发
yarn client:dev
yarn server:dev
在浏览器控制台中引发错误
产品
yarn client:prod
yarn server:prod
工作良好
此engine.io-parser+4.0.1.patch
补丁修复了
diff --git a/node_modules/engine.io-parser/lib/index.js b/node_modules/engine.io-parser/lib/index.js
index a412b46..b9f7d50 100644
--- a/node_modules/engine.io-parser/lib/index.js
+++ b/node_modules/engine.io-parser/lib/index.js
@@ -1,5 +1,5 @@
-const encodePacket = require("./encodePacket");
-const decodePacket = require("./decodePacket");
+const encodePacket = require("./encodePacket.browser");
+const decodePacket = require("./decodePacket.browser");
const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
感谢Ramil
请参阅此提交以获取更多信息