Problem description
Trying to include the Facebook module inside a CommonJS module fails.
Code to reproduce
app.js
var fb = require('ui/facebook');
fb.post();
ui/facebook.js
exports.post = function() {
var fb = require('facebook');
fb.appid = Ti.App.Properties.getString('ti.facebook.appid');
fb.permissions = ['publish_stream'];
fb.forceDialogAuth = true;
fb.authorize();
};
Notes
Moving the content of the function from ui/facebook.js to app.js solves the problem. The module is registered in tiapp.xml, as well as the property ti.facebook.appid.
The module is not defined; this means, the
authorize
method is invalid in the sample above.
[~dcassenti] How does it fail?
[~ingo] I found out the reason why this is happening. Since the file where the facebook module is required is called
facebook.js
, the file which is actually loaded is theui/facebook.js
itself. Renaming it to something different solves the problem. However, in iOS it seems like the Facebook module has priority over the file in the same directory, so the code works fine.