Search code examples
vue.jsnuxt.jspeerjs

Error while integrating peerjs with nuxtjs (vue.js)


installing:

npm i peerjs

/plugins/peerjs.js

import Peer from 'peerjs'

export default Peer

nuxt.config.js

plugins: [
  { src: "~/plugins/peerjs.js", ssr: true }
],

Browser error:

client.js?06a0:103 TypeError: Cannot set properties of undefined (setting '_events') at i (peerjs.min.js?a0bc:46) at i (peerjs.min.js?a0bc:66) at _callee2$ (index.js?f26e:87) at tryCatch (runtime.js?96cf:63) at Generator.invoke [as _invoke] (runtime.js?96cf:294) at Generator.eval [as next] (runtime.js?96cf:119) at asyncGeneratorStep (asyncToGenerator.js?1da1:3) at _next (asyncToGenerator.js?1da1:25) _callee$ @ client.js?06a0:103 tryCatch @ runtime.js?96cf:63 invoke @ runtime.js?96cf:294 eval @ runtime.js?96cf:119 asyncGeneratorStep @ asyncToGenerator.js?1da1:3 _next @ asyncToGenerator.js?1da1:25 eval @ asyncToGenerator.js?1da1:32 eval @ asyncToGenerator.js?1da1:21 eval @ client.js?06a0:65 Promise.catch (asíncrono) eval @ client.js?06a0:115 eval @ client.js:1294 ./.nuxt/client.js @ app.js:35 webpack_require @ runtime.js:854 fn @ runtime.js:151 0 @ app.js:9767 webpack_require @ runtime.js:854 checkDeferredModules @ runtime.js:46 webpackJsonpCallback @ runtime.js:33 (anónimo) @ app.js:1


Solution

  • Setting { src: '~/plugins/peerjs.js' , mode: 'server'} fixed the issue.

    Strange since it should either be mode: 'client' as shown in the documentation but I guess that PeerJS relies in fact on Node and not on client's window.