sockjs-client: global is not defined
What is global and why it is not defined?
Uncaught ReferenceError: global is not defined
at Object../node_modules/sockjs-client/lib/utils/browser-crypto.js (browser-crypto.js:3)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/sockjs-client/lib/utils/random.js (random.js:4)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/sockjs-client/lib/utils/event.js (event.js:3)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/sockjs-client/lib/transport/websocket.js (websocket.js:3)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/sockjs-client/lib/transport-list.js (transport-list.js:5)
at __webpack_require__ (bootstrap:76)
node -v v10.0.0 npm -v 6.1.0 sockjs-client 1.1.4
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 13
- Comments: 16 (1 by maintainers)
@cawena just define it yourself before other js script files, eg. in
headsection:use built version
import sockjs from "sockjs-client/dist/sockjs"Thanks @rechardlc that worked for me!
For TS folks, I got the types back by adding a
sockjs-client.d.tswithis there a proper fix planned to be added ?
globalis only available in a Node.js environment. If you want to use this library in a browser, you need to use the built version or build it yourself. In my build process,browserifyis used to replaceglobalwithwindowamong other things.any updates?
I have the same issue when I upgrade Angular from 5.X to 6.x and rxjs 5.x to 6.x. What I have to change?
This one works fine for me.
sockjs-client.d.tssomecode.tsit works, thanks 🎉
You might get eslint / build errors in this code block:
If so, then use this one instead (copy-pasted from @types/sockjs-client and re-arranged a little):
To use SockJS in your .ts files, import it like this: