import * as SockJS from "sockjs-client";
export function socketProvider() {
return new SockJS('http://localhost:8080/stomp');
}
- 对于new SockJS 函数报下面的异常
browser-crypto.js:3 Uncaught ReferenceError: global is not defined
at 1235 (browser-crypto.js:3:1)
at __webpack_require__ (bootstrap:19:1)
at 4531 (random.js:3:14)
at __webpack_require__ (bootstrap:19:1)
at 8698 (event.js:3:14)
at __webpack_require__ (bootstrap:19:1)
at 583 (websocket.js:3:13)
at __webpack_require__ (bootstrap:19:1)
at 5347 (transport-list.js:5:3)
at __webpack_require__ (bootstrap:19:1)
- 这个global是sockjs-client需要使用的,对于sockjs-client来说global就是window。
我们在index.html定义global
<script>
var global = window; // fix global is undefined in socketjs-client
</script>
it’s good