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

I am trying to use ratchet to reflect the changes made to my database in real time. I used the pusher application code ( http://socketo.me/docs/push ). But I get an error in this.

At the time of opening the client 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 that I typed: conn.subscribe ('topic'); // This is a subscription to the topic.

Now, when I make changes to this topic, an error appears in which the changes will 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?

+6
source share
2 answers

This can be resolved 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.

+5
source

This is because you are using if.js without using a modular system like AMD.

The docs explain how to convert a file to work in a browser using browserify if you did n

browser environment (via browser)

Since when.js is primarily aimed at modular environments, by default it does not export to a global object ( window in browsers). You can create your own if.js assembly using a browser if you prefer not to use the AMD or CommonJS loader in your project.

  • git clone https://github.com/cujojs/when
  • npm install
  • npm run browserify to generate build/when.js
    • Or npm run browserify-debug to create with on / monitor / console
  • <script src="path/to/when/build/when.js"></script>
    • when will be available as window.when
    • Other modules will be available as sub-objects / functions, for example. window.when.fn.lift , window.when.sequence . See the full list of subspaces in the browser build file.
+2
source

Source: https://habr.com/ru/post/953360/


All Articles