xmpp.js
xmpp.js copied to clipboard
Uncaught Error: Module "crypto" has been externalized for browser compatibility. Cannot access "crypto.randomBytes" in client code.
Describe the bug I'm unable to use the xmpp library because of crypto module
Logs null:1893 Uncaught Error: Module "crypto" has been externalized for browser compatibility. Cannot access "crypto.randomBytes" in client code. at Object.get (null:1893:17) at node_modules/ws/lib/websocket.js (null:3587:11) at __require2 (chunk-NKHIPFFU.js?v=2e0b079c:15:50) at node_modules/ws/index.js (null:4785:21) at __require2 (chunk-NKHIPFFU.js?v=2e0b079c:15:50) at node_modules/@xmpp/websocket/lib/Socket.js (null:4800:14) at __require2 (chunk-NKHIPFFU.js?v=2e0b079c:15:50) at node_modules/@xmpp/websocket/lib/Connection.js (null:4907:18) at __require2 (chunk-NKHIPFFU.js?v=2e0b079c:15:50)
Environment Node 18
Works fine for me on Node.js 18
Are you running in Node.js or the browser? How are you loading xmpp.js ?
@sonnyp I'm running in the browser in a nuxt project like this:
import { client, xml } from '@xmpp/client'
const xmpp= client(xmppConfig)
xmpp.on('online', () => {
xmpp.send(xml('presence'))
})
xmpp.start().catch(console.error) // eslint-disable-line
Looks like the code was executing in the browser?
If so - ws shouldn't be used - could be an issue with nuxt.
@xmpp/websocket package.json contains the following:
"browser": {
"ws": false
},