[TIMOB-5958] Regression: require() for non-CommonJS, when called from a require()d CommonJS, assumes ".js", crashes app
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-01-09T14:37:01.000+0000 |
Affected Version/s | Release 1.8.0 |
Fix Version/s | Release 1.8.0.1 |
Components | Android |
Labels | dr-list, regression |
Reporter | Shawn Lipscomb |
Assignee | Bill Dawson |
Created | 2011-11-02T07:17:07.000+0000 |
Updated | 2014-06-19T12:44:27.000+0000 |
Description
Using SDK 1.8.0.v20111010113820 and later, when a native module is require()d from within a CommonJS module, the following runtime error is generated (immediately upon running the app in the Android emulator):
{panel:title=Error| borderStyle=dashed| titleBGColor=red| bgColor=white}
ReferenceError: "NOT_FOUND" is not defined. (app://com.thirdpartycompany.specialmodule.js#1)
{panel}
In SDK 1.8.0.v20110913...., there is no problem.
Simply using require() to pull in the native module works fine, as long as it is called from a js file that hasn't been require()d into the app (e.g. app.js).
From the error message (ReferenceError: "NOT_FOUND" is not defined. (app://com.thirdpartycompany.specialmodule.js#1)), it's obvious that Titanium is appending ".js" to the module name, assuming it is a CommonJS module. But it is a *native* module, so Titanium shouldn't being trying to append ".js" to it.
My "require()" call is like this;
var SpecialModule=require('com.thirdpartycompany.specialmodule');
In the Application Installer window, I can see that it found the module:
[DEBUG] Detecting modules in C:\Titanium\Workspace\MyApp\modules
[DEBUG] Detected module for android: com.thirdpartycompany.specialmodule 1.9 @ C:\Titanium\Workspace\MyApp\modules\android\com.thirdpartycompany.specialmodule\1.9
According to Bill Dawson:
_...using the require for a native module inside a commonjs module. I can imagine what's happening there -- while executing the commonjs require, rhino likely hijacks "require", meaning our "require" gets ignored so it mises that step that checks first for a native module. I'll find a solution._
Simple sample code:
var Procs=require('CommonProcs'); // my commonJS unit
var TheWindow=Ti.UI.createWindow({
layout:'vertical',
exitOnClose:true,
navBarHidden:true
});
var TheLabel=Ti.UI.createLabel({
color:'white',
text:'Hello World',
font:{fontSize:'18dp',fontFamily:'Helvetica Neue'},
width:'auto'
});
TheWindow.add(TheLabel);
TheWindow.open();
var SpecialModule=require('com.thirdpartycompany.specialmodule');
exports.Foo=function()
{
SpecialModule.Bar();
};
I have also attached an actual project example that can be run.
Attachments
File | Date | Size |
---|---|---|
RequireNativeTest.zip | 2011-11-02T07:17:07.000+0000 | 377605 |
I know we're still working on enabling modules in master, but it would be cool if this one could get worked on shortly after that integration happens. Thanks...
@SHAWN can you verify if this is an issue still for you with the production 1.8.0.1? Thank you
Bill, I'm trying to get my test project to run on 1.8.0.1. Can't get the 2.0 version of the AdMod module to work at all (same problem as multiple Q&A posters are having). I will let you know when I have a result.
Got it working. This bug has proven to be fixed in SDK 1.8.0.1 with V8. Thanks Bill!
closing