{ "id": "168818", "key": "TIMOB-24932", "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": "19870", "description": "", "name": "Release 6.1.2", "archived": false, "released": true, "releaseDate": "2017-08-03" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2017-07-11T16:57:48.000+0000", "created": "2017-07-05T08:45:24.000+0000", "priority": { "name": "Critical", "id": "1" }, "labels": [ "android", "module" ], "versions": [], "issuelinks": [], "assignee": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "updated": "2017-07-20T22:29:16.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": "Suppose that I have a module is called {{it.andreavitale.commonjs.test}}:\r\nit has a {{it.andreavitale.commonjs.test.js}} file inside {{my-module/android/assets}} folder and a proxy file under {{my-module/android/src/it/andreavitale/commonjs/test/ExampleProxy.java}}\r\n\r\nIf inside {{it.andreavitale.commonjs.test.js}} file I call {{require('it.andreavitale.commonjs.test').createExample()}} I always get this error:\r\n\r\n{code:java}\r\n[ERROR] TiExceptionHandler: (main) [126,126] ----- Titanium Javascript Runtime Error -----\r\n[ERROR] TiExceptionHandler: (main) [0,126] - In ti:/module.js:129,37\r\n[ERROR] TiExceptionHandler: (main) [0,126] - Message: Uncaught TypeError: Cannot read property 'length' of undefined\r\n[ERROR] TiExceptionHandler: (main) [0,126] - Source: var invocationsLen = invocationAPIs.length;\r\n[ERROR] V8Exception: Exception occurred at ti:/module.js:129: Uncaught TypeError: Cannot read property 'length' of undefined\r\n{code}\r\n\r\nIf I call {{require('it.andreavitale.commonjs.test').createExample()}} inside my app alloy.js the proxy is correctly created.\r\n\r\nI attach a sample module project to reproduce the error.\r\nIf you comment the line {{9}} inside {{android/assets/it.andreavitale.commonjs.test.js}} and you run the example app everything will work fine.", "attachment": [ { "id": "62831", "filename": "commonjs-test.zip", "author": { "name": "Andrea.Vitale", "key": "andrea.vitale", "displayName": "Andrea Vitale", "active": true, "timeZone": "Europe/Berlin" }, "created": "2017-07-05T08:39:45.000+0000", "size": 867279, "mimeType": "application/zip" }, { "id": "62832", "filename": "it.andreavitale.commonjs.test-android-1.0.0.zip", "author": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "created": "2017-07-05T11:48:36.000+0000", "size": 50553, "mimeType": "application/zip" } ], "flagged": false, "summary": "Android Hybrid modules: cannot instantiate a proxy in a js file that is packaged in the same module", "creator": { "name": "Andrea.Vitale", "key": "andrea.vitale", "displayName": "Andrea Vitale", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "Andrea.Vitale", "key": "andrea.vitale", "displayName": "Andrea Vitale", "active": true, "timeZone": "Europe/Berlin" }, "environment": "macOS Sierra\r\nTiSDK 6.1.0.GA", "comment": { "comments": [ { "id": "423482", "author": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "body": "I am able to reproduce the issue using the below\r\n\r\nTi SDK: 6.1.1.GA\r\nOnePlus 3 7.1.1\r\n\r\n# Add the attached module zip (it.andreavitale.commonjs.test-android-1.0.0.zip) either globally or in your app\r\n# Add the below code and tiapp module entry to your app\r\n# Build for Android (device or emulator)\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({ backgroundColor: 'green', layout: 'vertical' });\r\nvar x = require(\"it.andreavitale.commonjs.test\");\r\nx.sayHello();\r\nwin.open();\r\n{code}\r\n\r\n{code}\r\n\r\n it.andreavitale.commonjs.test\r\n\r\n{code}", "updateAuthor": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "created": "2017-07-05T11:48:51.000+0000", "updated": "2017-07-05T11:48:51.000+0000" }, { "id": "423668", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "So I'm not entirely sure this is really a bug here, or at least I think there's a simple workaround to avoid this. What happens when we create a hybrid module is that the CommonJS file and the native module get \"merged\". In practice what that really means is that we instantiate the native module, then we load the commonjs file as a module and \"copy\" all the own properties of the module.exports from it onto the native module's wrapper object.\r\n\r\nSo in this case, if you wanted to invoke the native module's createExample() in the commonjs portion, you'd actually call {{this.createExample();}}\r\n\r\nHere's the whole file:\r\n{code:javascript}\r\nmodule.exports = {\r\n secondFile: require(\"it.andreavitale.commonjs.test/another.file\"),\r\n sayHello: function() {\r\n alert('hello');\r\n\r\n Ti.API.info(\"Creating Example proxy\");\r\n\r\n // This will not work\r\n // return require(\"it.andreavitale.commonjs.test\").createExample();\r\n //This WILL work\r\n return this.createExample();\r\n }\r\n};\r\n{code}\r\n\r\nCalling {{require(\"module.id\")}} from the commonjs extension file may just confuse the system a bit. I think specifically our caching of the combined native + CommonJS is somehow getting confused in this specific case. We cache the native module portion globally, but the combined native+CommonJS portion gets cached per-module (i.e. we try to re-generate it from each module that attempts to require it). We may still need to investigate and better handle this issue, but for now please just use \"this\".", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2017-07-07T17:51:55.000+0000", "updated": "2017-07-07T17:53:47.000+0000" }, { "id": "423671", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "6.1.2: https://github.com/appcelerator/titanium_mobile/pull/9206\r\nmaster: https://github.com/appcelerator/titanium_mobile/pull/9207", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2017-07-07T19:21:04.000+0000", "updated": "2017-07-07T19:21:04.000+0000" }, { "id": "423915", "author": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Passing review according to [~eharris]'s comments in the PR.", "updateAuthor": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-07-11T16:57:48.000+0000", "updated": "2017-07-11T16:57:48.000+0000" }, { "id": "424076", "author": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket. The changes are compiled to a binary so I cannot see the actually. However by grepping contents, I am able to see ASCII texts in the file that was changed. Changes are in SDK 6.1.2.v20170710160853.", "updateAuthor": { "name": "amukherjee", "key": "amukherjee", "displayName": "Abir Mukherjee", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-07-13T15:50:11.000+0000", "updated": "2017-07-13T15:50:11.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }