Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require.js loading issue #52

Closed
nlegoff opened this issue Feb 21, 2014 · 13 comments
Closed

Require.js loading issue #52

nlegoff opened this issue Feb 21, 2014 · 13 comments

Comments

@nlegoff
Copy link

nlegoff commented Feb 21, 2014

When loading autobahn as an AMD module I get the following error
Uncaught ReferenceError: ab is not defined with the following sample :

<!DOCTYPE html>
<html>
<body>
<script src="//requirejs.org/docs/release/2.1.11/minified/require.js"></script>
<script>
    require.config({
        baseUrl: ".",
        paths: {
            "autobahn": "//autobahn.s3.amazonaws.com/js/autobahn",
            "when": "//cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
        },
        shim: {
            "autobahn": {
                deps: ["when"]
            }
        }
    });
    require(["autobahn"], function(autobahn) {
        console.log(autobahn);
    });
</script>
</body>
</html>

Am I doing something wrong or is this a bug ? I've looking for previous PR and it seems #49 should have corrected this problem according to @hugohenrique who related the same issue in #35 .

@hugohenrique
Copy link
Contributor

Yes the error continues. Seems to me that in the new version ends this problem.

@nlegoff
Copy link
Author

nlegoff commented Feb 21, 2014

I looked at the source code and it seems that there is two problems

  • The autobahn.js file defines two modules (autobahn & when) which is forbidden. There should only be one module definition per file on disk.
  • Some methods of the "autobahn object" are defined outside the module definition.

@nlegoff
Copy link
Author

nlegoff commented Feb 21, 2014

@oberstet

Currently AMD loading can not work as it is.

The simplest solution to this problem would be to build two file :

  • autobahn.js (with when.js)
  • autobahn.amd.js (without when.js)

The autobahn.js file can be provided in a single file with when module inside nevertheless we must point out that the "exports" feature in requireJS would not work as expected due to the when module definition see http://requirejs.org/docs/api.html#config-shim

    require.config({
        baseUrl: ".",
        paths: {
            "autobahn": "//autobahn.s3.amazonaws.com/js/autobahn"
        },
        shim: {
            "autobahn": {
                exports: 'ab'
            }
        }
    });

The autobahn.amd.js would not include include when module and therefore would require when as a module dependency in the require.js configuration.

require.config({
        baseUrl: ".",
        paths: {
            "autobahn": "//autobahn.s3.amazonaws.com/js/autobahn",
            "when": "//cdnjs.cloudflare.com/ajax/libs/when/2.7.1/when"
        },
        shim: {
            "autobahn": {
                deps: ["when"]
            }
        }
    });

What do you think about it ?

@oberstet
Copy link
Contributor

Are you having the issue with the old WAMP v1 implementation?

https://github.com/tavendo/AutobahnJS/tree/wamp1
https://autobahn.s3.amazonaws.com/js/autobahn.js

or the new AutobahnJS for WAMP v2

https://github.com/tavendo/AutobahnJS
https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.js

?

The new AutobahnJS is built for browsers using Browserify. The old AutobahnJS did include manual code trying to make it compatible with usual module systems.

@oberstet
Copy link
Contributor

If this refers to the old AutobahnJS (WAMPv1) implementation: this is no longer supported anyway. If the issue is for the new implementation, please reopen ..

@galthron
Copy link

Ive got the same error. Any solution ? I think i tried every possible configuration. I tried to use autobahn directly from autobahn.s3.amazonaws.com/js/autobahn and also i installed it through bower. In first case ive got an error "ReferenceError: ab is not defined" and in second case its seem that there is e problem with loading "submodules" as when and session and the other that are required by autobahn. "ReferenceError: module is not defined module.exports = require('./lib/autobahn');" so it look like there is problem with module.export. I tried to load all libs manually without any success. I will be very very gratefull for any advice , how to run autobahn with requirejs , it took me too much time already. Btw. i`m using the newest version.

@oberstet
Copy link
Contributor

@oberstet
Copy link
Contributor

@galthron
Copy link

galthron commented Mar 2, 2014

Thanks. That works. But there is another issue. Im using Rachet(http://socketo.me/) Wamp, and ive got this error: Protocol violation: unexpected message type 0, server response is
[0, "5313c015641d6", 1, "Ratchet/0.3"],
i did a little check and it look like 0 (first in array) in Ratchet is Welecome message, but in autobahn is 2 (but i`m not sure is this is a problem). I wonder is that have something to do witch autobahn update to v2. Or maybe problem is somewhere else.

@oberstet
Copy link
Contributor

oberstet commented Mar 3, 2014

Probably Ratchet is not yet on version 2 of WAMP ..

@cboden
Copy link

cboden commented Mar 3, 2014

Ratchet is still on v1. You should use the AutobahnJS version that is compatible with v1 of the WAMP protocol.

@oberstet
Copy link
Contributor

oberstet commented Mar 3, 2014

@galthron In this case, you should use:

https://github.com/tavendo/AutobahnJS/tree/wamp1
https://autobahn.s3.amazonaws.com/js/autobahn.js

@cboden Any plans to upgrade Ratchet to v2?

@cboden
Copy link

cboden commented Mar 4, 2014

I do plan to. I just haven't had much time for OS lately, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants