Search code examples
phpzeromqratchet

Ratchet / When.js: "Uncaught ReferenceError: module is not defined"


I'm trying to use ratchet for reflecting the changes made to my database realtime. I used the code of the pusher app (http://socketo.me/docs/push). But i am getting error in that.

The moment I open the client side page :

Uncaught ReferenceError: module is not defined                    when.js:900
(anonymous function)                                              when.js:900
(anonymous function)                                              when.js:15
(anonymous function)                                              when.js:900

After this I typed: conn.subscribe('topic'); //This subscribes the topic.

Now the moment I make changes to this topic, an error pops up where the changes are to be displayed.

Error 2 :

Uncaught TypeError: undefined is not a function         [VM] autobahn.min.js (124):66
(anonymous function)                                    [VM] autobahn.min.js (124):66
c._websocket.onmessage                                  [VM] autobahn.min.js (124):66

Any help ?


Solution

  • This may be solvable by using the following JavaScript before including the when.js file:

    window.define = function(factory) {
        try{ delete window.define; } catch(e){ window.define = void 0; } // IE
        window.when = factory();
    };
    window.define.amd = {};
    

    Then, include your when.js file.