{ "id": "172591", "key": "TIMOB-26543", "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": [], "resolution": null, "resolutiondate": null, "created": "2018-11-10T19:59:46.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-11-12T11:33:58.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" }, { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "We noticed two weird glitches between iOS and Android: \r\n1. The \"utils\" module seems to be treated quite special on iOS, because the kroll-core thinks we want to use \"Ti.Utils\" - whyever that is\r\n2. If the \"utils\" module causing an error in Alloy controller if require'd via {{./utils}} on Android, but works fine on iOS.\r\n\r\nTo replicate, simply create a new Alloy project and add a file \"utils.js\" to app/lib. Then, create a sub-controller, let's day {{controllers/test/index.js}} and try to import/require it from there\r\n\r\nThe app crashes on Android, works fine on iOS. \r\n\r\nWorkaround: Rename the file to something like \"app-utils\".", "attachment": [], "flagged": false, "summary": "TiAPI: require() behavior differs across platforms", "creator": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "environment": null, "comment": { "comments": [ { "id": "443487", "author": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "body": "1) The {{utils}} module behaviour only happens as a fallback if just use the word {{utils}} as the module, using an absolute or relative path fixes this issue. When requiring a file from libs in a controller you almost always wanna use an absolute path.\r\n2) This looks like a parity bug, {{require('./utils')}} where utils resides under lib should not work from any controller to my knowledge. The files don't reside in the same folder so _shrug_, I wouldn't agree that this is a major issue however.\r\n\r\nCan you confirm the code below is correct? We can probably distill that down to a pure classic example.\r\n\r\n{code: title=lib/utils.js}\r\nmodule.exports = 'fff';\r\n{code}\r\n\r\n{code: title=views/index.xml}\r\n\r\n\t\r\n\t\t\r\n\t\r\n\r\n{code}\r\n\r\n{code: title=controllers/index.js}\r\nfunction doClick(e) {\r\n\tAlloy.createController('/sub/index.js').getView().open()\r\n}\r\n\r\n$.index.open();\r\n{code}\r\n\r\n{code: title=views/sub/index.xml}\r\n\r\n\t\r\n\t\t\r\n\t\r\n\r\n{code}\r\n\r\n{code: title=controllers/sub/index.js}\r\nfunction doClick(e) {\r\n\tconst util = require('./utils');\r\n\talert(util);}\r\n\r\n$.index.open();\r\n{code}", "updateAuthor": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "created": "2018-11-12T11:23:15.000+0000", "updated": "2018-11-12T11:23:15.000+0000" }, { "id": "443489", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "[~eharris] I agree it is not major, since a workaround is applicable. It's still something many people run into and takes a good bunch of time to properly find out what's going on. Your example sounds correct and probably even works, but in our case, we used ES6+ imports and they all crashed. E.g.:\r\n{code}\r\nimport Utils from 'utils';\r\nimport { method1, method2 } from 'utils';\r\n{code}\r\n", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-11-12T11:33:46.000+0000", "updated": "2018-11-12T11:33:46.000+0000" } ], "maxResults": 2, "total": 2, "startAt": 0 } } }