{ "id": "82231", "key": "TIMOB-5958", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "12580", "description": "Dual Runtime 1.8.0", "name": "Release 1.8.0.1", "archived": true, "released": true, "releaseDate": "2011-12-22" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2012-01-09T14:37:01.000+0000", "created": "2011-11-02T07:17:07.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "dr-list", "regression" ], "versions": [ { "id": "11331", "description": "", "name": "Release 1.8.0", "archived": true, "released": true, "releaseDate": "2011-10-31" } ], "issuelinks": [], "assignee": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2014-06-19T12:44:27.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "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):\r\n\r\n{panel:title=Error| borderStyle=dashed| titleBGColor=red| bgColor=white}\r\nReferenceError: \"NOT_FOUND\" is not defined. (app://com.thirdpartycompany.specialmodule.js#1)\r\n{panel} \r\n\r\nIn SDK 1.8.0.v20110913...., there is no problem.\r\n\r\nSimply 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).\r\n\r\nFrom 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.\r\n\r\nMy \"require()\" call is like this;\r\n\r\n{code:borderStyle=solid}\r\nvar SpecialModule=require('com.thirdpartycompany.specialmodule');\r\n{code}\r\n\r\nIn the Application Installer window, I can see that it found the module:\r\n\r\n{code:borderStyle=solid}\r\n[DEBUG] Detecting modules in C:\\Titanium\\Workspace\\MyApp\\modules\r\n[DEBUG] Detected module for android: com.thirdpartycompany.specialmodule 1.9 @ C:\\Titanium\\Workspace\\MyApp\\modules\\android\\com.thirdpartycompany.specialmodule\\1.9\r\n{code}\r\n\r\nAccording to Bill Dawson:\r\n_...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._\r\n\r\nSimple sample code:\r\n{code:title=app.js|borderStyle=solid}\r\nvar Procs=require('CommonProcs'); // my commonJS unit\r\n\r\nvar TheWindow=Ti.UI.createWindow({\r\n layout:'vertical',\r\n exitOnClose:true,\r\n navBarHidden:true \r\n });\r\nvar TheLabel=Ti.UI.createLabel({\r\n color:'white',\r\n text:'Hello World',\r\n font:{fontSize:'18dp',fontFamily:'Helvetica Neue'},\r\n width:'auto'\r\n });\r\nTheWindow.add(TheLabel);\r\n \r\nTheWindow.open();\r\n{code}\r\n\r\n{code:title=CommonProcs.js|borderStyle=solid}\r\nvar SpecialModule=require('com.thirdpartycompany.specialmodule');\r\n\r\nexports.Foo=function()\r\n{\r\n SpecialModule.Bar();\r\n};\r\n{code}\r\n\r\nI have also attached an actual project example that can be run.\r\n", "attachment": [ { "id": "23988", "filename": "RequireNativeTest.zip", "author": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "created": "2011-11-02T07:17:07.000+0000", "size": 377605, "mimeType": "application/zip" } ], "flagged": false, "summary": "Regression: require() for non-CommonJS, when called from a require()d CommonJS, assumes \".js\", crashes app", "creator": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "subtasks": [], "reporter": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "environment": "Windows XP, Android emulator (2.2) and device (HTC Aria)\r\nSDK 1.8.0.v20111010113820", "comment": { "comments": [ { "id": "173737", "author": { "name": "kwhinnery", "key": "kwhinnery", "displayName": "Kevin Whinnery", "active": true, "timeZone": "America/Chicago" }, "body": "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...", "updateAuthor": { "name": "kwhinnery", "key": "kwhinnery", "displayName": "Kevin Whinnery", "active": true, "timeZone": "America/Chicago" }, "created": "2011-11-22T11:06:25.000+0000", "updated": "2011-11-22T11:06:25.000+0000" }, { "id": "178308", "author": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "body": "@SHAWN can you verify if this is an issue still for you with the production 1.8.0.1? Thank you", "updateAuthor": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "created": "2012-01-05T19:40:30.000+0000", "updated": "2012-01-05T19:40:30.000+0000" }, { "id": "178329", "author": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "body": "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.", "updateAuthor": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "created": "2012-01-06T07:52:40.000+0000", "updated": "2012-01-06T07:52:40.000+0000" }, { "id": "178340", "author": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "body": "Got it working. This bug has proven to be fixed in SDK 1.8.0.1 with V8. Thanks Bill!", "updateAuthor": { "name": "bitshftr", "key": "bitshftr", "displayName": "Shawn Lipscomb", "active": true, "timeZone": "America/New_York" }, "created": "2012-01-06T08:55:10.000+0000", "updated": "2012-01-06T08:55:10.000+0000" }, { "id": "179960", "author": { "name": "thomashuelbert", "key": "thomashuelbert", "displayName": "Thomas Huelbert", "active": true, "timeZone": "America/Los_Angeles" }, "body": "closing", "updateAuthor": { "name": "thomashuelbert", "key": "thomashuelbert", "displayName": "Thomas Huelbert", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-01-19T16:37:03.000+0000", "updated": "2012-01-19T16:37:03.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }