Openvidu-browser : window is not defined - nuxt.js

Hello @pabloFuente
I developing on nuxt.js
when I import openvidu-browser, shows error like
window is not defined (error occur from openvidu-browser node modules)
this is because nuxt is server side so openvidu-browser is for client side
how to resolve this?
I tried by import as plugin “ssr:false” in nuxt.config.js but same error.
how to resolve this?
thanks

Jin

We don’t have experience with Nuxt.js.

If nuxt is server side, openvidu-browser won’t work on it.

Regards

thanks.
I solved this.

If you share how you have solved it, other users can take a look to it.

sure!
when import openvidu-browser on server side code , shows many errors 'cause this module can only run on frotnend side
so I resovle this as below:
in joinSession() method
if (process.client) {
}
this is for run codes on only frontend side
so we should import openvidu-browser in this part
but it will show below message on console:
" import' and 'export' may only appear at the top level vuejs "
so I also resolve like below:(I attached full code)

       joinSession () {
                if (process.client) {
                    import('openvidu-browser').then((OpenViduModule) => {
                        this.OV = new OpenViduModule.OpenVidu()
                        this.session = this.OV.initSession()
                        this.subscribeToStreamCreated()
                        this.connectToSession()
                    })
                }
            }

if have any some question, let me know
thanks

Jin

Thanks! It will help to other Nuxt.js users with the same problem.

1 Like