Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15663] Android: Cannot require Facebook module inside a CommonJS module

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
LabelssupportTeam
ReporterDavide Cassenti
AssigneeUnknown
Created2013-11-05T15:35:32.000+0000
Updated2018-02-28T20:04:05.000+0000

Description

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.

Comments

  1. Ingo Muschenetz 2013-11-05

    [~dcassenti] How does it fail?
  2. Davide Cassenti 2013-11-06

    [~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 the ui/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.

JSON Source