Search code examples
node.jsopentok

window is not defined in opentok-text-chat node module


I am working in node js. I installed opentok-text-chat using npm. Then I started using node server.js, it returns following error:

E:\simerjit\dawai\node_modules\opentok-text-chat\dist\opentok-text-chat.js:14
    window.jQuery = $;
    ^

ReferenceError: window is not defined
    at Object.<anonymous> (E:\simerjit\dawai\node_modules\opentok-text-chat\dist
\opentok-text-chat.js:14:5)
    at Object.<anonymous> (E:\simerjit\dawai\node_modules\opentok-text-chat\dist
\opentok-text-chat.js:608:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (E:\simerjit\dawai\server\routes.js:28:32)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)

Solution

  • The opentok-text-chat library is a client-side library, it can help you add text chat functionality to your opentok application.

    It is not a server-side node library, therefore it causes this error when it tries to access the window object which doesn't exist in node.

    You can check out the library documentation quick start here https://github.com/opentok/accelerator-textchat-js#quick-start

    or see one of the example applications here https://github.com/opentok/accelerator-sample-apps-js