今天在 vue3 中引入 sockjs-client 的时候莫名的报了个错,而且页面里也没有global相关的内容,使得 sockjs-client 无法使用。报错信息如下: 代码语言:javascript 复制 Uncaught ReferenceError:global is not defined at node_modules/sockjs-client/lib/utils/event.js(event.js:8:27)at__require2(chunk-A5AMJUWA....
declare module "sockjs-client/dist/sockjs" { export default (await import("sockjs-client")).default } If so, then use this one instead (copy-pasted from @types/sockjs-client and re-arranged a little): declare namespace SockJSN { type CONNECTING = 0; type OPEN = 1; type CLOSING = 2...
event.js:8 Uncaught ReferenceError: global is not defined at node_modules/sockjs-client/lib/utils/event.js (event.js:8) at __require (chunk-T7KYDC53.js?v=a7e674ed:6) at node_modules/sockjs-client/lib/transport/websocket.js (websocket.js:3) at __require (chunk-T7KYDC53.js?v=a7e674...
然后,您可以像这样在组件或服务中导入socket.io-client
vue 3 버전으로 sockjs를 이용하여 간단한 채팅을 만들어보고 있는데, 다음과 같은 에러가 났다. event.js:8 Uncaught ReferenceError: global is not defined at node_modules/sockjs-client/lib/utils
import SockJs from 'sockjs-client/dist/sockjs.min.js' and u sure to add .d.ts in your workspace : // socket.d.ts declare module 'sockjs-client/dist/sockjs.min.js' { import Client from 'sockjs-client'; export default Client; } 👍 4 github-actions bot commented Oct 27, 2021 Thi...