mkuklis / phonegap-websocket

Websocket PhoneGap plugin for Android
203 stars 78 forks source link

require() conflict with dojo #38

Closed dhuyvett closed 10 years ago

dhuyvett commented 10 years ago

I just hit a problem using the plug-in in a dojo mobile app. The line:

var exec = require('cordova/exec');

seems to have been trying to use require() from dojo instead of from cordova. This was failing, (dojo couldn't find the cordova/exec module) causing the whole definition of WebSocket to be skipped.

I resolved the problem by changing the line to:

var exec = cordova.require('cordova/exec');

I'm not sure whether this is the correct solution, only that it worked for me.

mkuklis commented 10 years ago

@dhuyvett that's interesting. I would assume every cordova/phonegap plugin would run into this problem right? I think your solution is correct. Would you mind creating a pull request? Thank you!

rgillan commented 10 years ago

We have been using this plugin with Dojo for a while. There's no issue when you use cordova.require (which is what is recommended/required). Dojo has an AMD loader for it's modules which are in a totally different namespace from cordova. We do all our cordova.require includes in our app.init function from deviceReady, and separately with dojo when the domReady is up.

mkuklis commented 10 years ago

Thank you for your input @rgillan! @dhuyvett please create a pull request and I will merge from here.

dhuyvett commented 10 years ago

On further investigation … this may be my problem. I'm using the plug-in with Worklight, which means I can't use cordova plugin add. I'm installing the plugin manually into my project.

If I install it in a regular cordova project using cordova plugin add, cordova automatically wraps phonegap-websocket.js in a cordova.define function with require as a local parameter. That should resolve the problem with require.

It looks like the way the code is now is probably correct, and that I need to fix the way I am manually adding the plug-in to my project

mkuklis commented 10 years ago

Ah I see. You are right about cordova wrapping it in the cordova.define I will close this one for now then. Cheers!