{ "id": "164542", "key": "TIMOB-24148", "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": "18154", "name": "Release 6.0.1", "archived": false, "released": true, "releaseDate": "2016-12-21" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2016-11-29T15:23:07.000+0000", "created": "2016-11-15T18:08:28.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "qe-6.0.0" ], "versions": [ { "id": "16980", "description": "New V8", "name": "Release 6.0.0", "archived": false, "released": true, "releaseDate": "2016-11-15" } ], "issuelinks": [], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2016-11-30T18:12:50.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": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "Creating a commonJS module or using library code files that share a name with internal native classes throws an error.\r\n\r\n{code}\r\n[ERROR] : Script Error {\r\n[ERROR] : column = 24;\r\n[ERROR] : line = 12;\r\n[ERROR] : message = \"undefined is not a function (evaluating 'util.test()')\";\r\n[ERROR] : sourceURL = \"file:///Users/Eric/Library/Developer/CoreSimulator/Devices/83A39029-8DC3-4231-90FA-C9394BF09F69/data/Containers/Bundle/Application/CF7DEB2C-4872-4B44-A119-48F7201E8CC8/checkit.app/alloy/controllers/index.js\";\r\n[ERROR] : stack = \"doClick@file:///Users/Eric/Library/Developer/CoreSimulator/Devices/83A39029-8DC3-4231-90FA-C9394BF09F69/data/Containers/Bundle/Application/CF7DEB2C-4872-4B44-A119-48F7201E8CC8/checkit.app/alloy/controllers/index.js:12:24\";\r\n[ERROR] : }\r\n{code}\r\n\r\n*Steps to reproduce issue*\r\n1. Create a new project\r\n2. Add a js file to the app/lib folder that has the name of an internal native class (utils.js, for example)\r\n3. Populate the file with an exported function\r\n4. Require the module in the index.js and call the exported function\r\n\r\n*Expected Results*\r\nThe exported function is called without issue\r\n\r\n*Actual Results*\r\nThe above error is thrown\r\n\r\n*Code*\r\nFor the default Alloy project, change the {{index.js}} to:\r\n{code}\r\nvar foo = require('utils');\r\nfunction doClick(e) {\r\n alert(foo.test());\r\n}\r\n\r\n$.index.open();\r\n{code}\r\n\r\nThen create a file called {{app/lib/utils.js}} (Alloy) or {{Resources/utils.js}} (Classic) and populate it with:\r\n{code}\r\nexports.test = function() {\r\n return \"I WAS CALLED\";\r\n};\r\n{code}", "attachment": [], "flagged": false, "summary": "iOS: CommonJS modules/Library code cannot share names with native classes", "creator": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "environment": "MacOS 10.12 (16A323)\r\nStudio 4.8.0.201611121409\r\nTi SDK 6.0.0.GA\r\nAppc NPM 4.2.8\r\nAppc CLI 6.0.0\r\nAlloy 1.9.4\r\nXcode 8.1 (8B62)", "comment": { "comments": [ { "id": "400995", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "As a side-note: You are actually able to use something like {{var md5 = require('utils').md5HexDigest('mystr');}} instead of {{var md5 = Ti.Utils.md5HexDigest('mystr');}} which is pretty amazing and more \"NodeJS'sh\". \r\n\r\nBut for the solution, we will now throw an error-log when the user tries to use the exact same name as one of the top moduels (UI, Utils, Filesystem, Calendar, ...) so they either prefix it correctly (e.g. {{require('./utils')}}, {{require('./filesystem')}}, ...) or rename it to something that does not collide. PR coming later today.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-11-15T19:45:23.000+0000", "updated": "2016-11-15T19:45:23.000+0000" }, { "id": "401100", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "PR (master): https://github.com/appcelerator/titanium_mobile/pull/8608\r\nPR (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8609", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-11-16T03:15:39.000+0000", "updated": "2016-11-16T03:15:39.000+0000" }, { "id": "401101", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "[~cwilliams] Thinking about a proper unit-test, we could check if the local commonJS module fails and the native Ti method succeeds. ", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-11-16T03:17:33.000+0000", "updated": "2016-11-16T03:17:33.000+0000" }, { "id": "402194", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "Fixes pushed to\r\nmaster: https://github.com/appcelerator/titanium_mobile/commit/9c564ab384ee3ea3c4e70a9d697eadf56fda0707\r\n6_0_X: https://github.com/appcelerator/titanium_mobile/commit/a6667488f527e09b10acadea90162c4bc6eb9d22", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2016-11-29T15:21:02.000+0000", "updated": "2016-11-29T15:21:02.000+0000" }, { "id": "402195", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "Note that there is no real \"fix\" here, but instead we now detect when there's a name clash using the old style un-prefixed requires, such as {{require('utils');}}\r\n\r\nIn that scenario where there's a clash between a native API/module and a JS file we will spit ou along warning to the logs stating that there was a collision and the native module/API was loaded in preference to the JS file, and if you intended to address the JS file you need to change the require to use a prefix such as {{require('./utils')}} or {{require('/utils')}}", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2016-11-29T15:23:03.000+0000", "updated": "2016-11-29T15:23:03.000+0000" }, { "id": "402274", "author": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Verified \"fixed\" using:\r\n\r\nMacOS 10.12 (16A323)\r\nStudio 4.8.0.201611121409\r\nTi SDK 6.0.1.v20161130023500\r\nAppc NPM 4.2.8\r\nAppc CLI 6.0.0\r\nAlloy 1.9.4\r\nXcode 8.1 (8B62)\r\n\r\nAs Chris stated, the fix here is to display a warning message to use {{./}} or {{/}} in order to use a CommonJS/library code with a naming conflict. This message is displayed when a conflict is detected and modifying the code, as described, will run without error.", "updateAuthor": { "name": "ewieber", "key": "ewieber", "displayName": "Eric Wieber", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2016-11-30T18:12:50.000+0000", "updated": "2016-11-30T18:12:50.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }