{ "id": "159763", "key": "TIMOB-23264", "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": "17706", "name": "Release 5.4.0", "archived": false, "released": true, "releaseDate": "2016-08-11" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2016-05-23T13:24:11.000+0000", "created": "2016-04-21T15:16:17.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [], "versions": [ { "id": "17706", "name": "Release 5.4.0", "archived": false, "released": true, "releaseDate": "2016-08-11" } ], "issuelinks": [], "assignee": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "updated": "2016-06-27T23:54:04.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": "12642", "name": "Windows", "description": "Windows authoring support" } ], "description": "When trying to load a CommonJS module (in my case http://github.com/Topener/To.ImageCache) it complained it couldn't find it even though it works on Android/iOS\r\n\r\nI had to move the js file to the lib folder for it to work again. \r\n\r\nWe need to support the legacy pattern of looking for moduleid/moduleid.js in Titanium CommonJS modules. Right now we require spec-compliant CommonJS directories: a package.json pointing to main; an index.js or an index.json.", "attachment": [], "flagged": false, "summary": "Windows: Unable to load CommonJS module with no package.json or index.js", "creator": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "environment": null, "closedSprints": [ { "id": 631, "state": "closed", "name": "2016 Sprint 11 SDK", "startDate": "2016-05-21T00:06:10.029Z", "endDate": "2016-06-04T00:06:00.000Z", "completeDate": "2016-06-06T07:30:39.854Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "383561", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello, \r\n\r\nAccording to the link here http://docs.appcelerator.com/platform/latest/#!/guide/Alloy_Controllers-section-34636384_AlloyControllers-LibraryCodeandCommonJSModules in section \"Library Code and CommonJS Modules\" \"Some JavaScript code might not be suitable as controller code, since it does not have an associated view, or you want to separate it from the MVC framework for easier reusability. Create a folder called lib in the app directory of your Alloy project. Add your CommonJS modules or JavaScript code using the CommonJS format into the lib folder. These files are copied to the Resources folder, when compiling your Alloy project. To use the library or CommonJS module, require it with the library name or module name without the 'app/lib' path and '.js' extension\". \r\n\r\nThis clearly stated that you add your CommonJS modules or JavaScript code using the CommonJS format into the lib folder. This should clear your concern. Hope this helps.\r\n\r\nRegards,\r\nSharif.\r\n\r\n\r\n\r\n\r\n", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2016-04-21T18:26:19.000+0000", "updated": "2016-04-21T18:26:19.000+0000" }, { "id": "383584", "author": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "body": "Does not clear my concern I'm afraid. It causes confusing and doesn't work like iOS and Android work, and especially not since commonjs modules are actually stimulated.", "updateAuthor": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-04-21T20:37:20.000+0000", "updated": "2016-04-21T20:37:20.000+0000" }, { "id": "383586", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "[~topener] So you had the commonjs module installed in the project or globally? And just did a {{require('To.ImageCache');}} and that failed?", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2016-04-21T20:46:05.000+0000", "updated": "2016-04-21T20:46:05.000+0000" }, { "id": "383591", "author": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "body": "Yes, it is installed as a commonjs module for both iOS and Android through `tiapp.xml` as a commonjs module. The require is indeed what I use and Windows phone says it cannot find the module.\r\n\r\nBy putting the file in the lib it works... but since I want a universal app, I want a universal configuration through modules!", "updateAuthor": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-04-21T20:53:49.000+0000", "updated": "2016-04-21T20:53:49.000+0000" }, { "id": "384477", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "[~topener] So it looks like this is a result of Windows being more spec-compliant with regards to CommonJS modules. When we require a directory (which is what we're doing for commonjs modules) we look for a package.json, then an index.js, then an index.json.\r\n\r\nI believe the legacy code for iOS/Android explicitly look for Titanium modules to have a JS file with the module-id.js name inside the folder.\r\n\r\nSo a couple things here:\r\n- An easy workaround for you is to add a package.json like so:\r\n{code}\r\n\r\n{\r\n \"description\": \"To.ImageCache\",\r\n \"directories\": {\r\n \"lib\": \".\"\r\n },\r\n \"main\": \"To.ImageCache\",\r\n \"name\": \"To.ImageCache\",\r\n \"version\": \"0.1\"\r\n}\r\n{code}\r\n- We should likely have some special logic in Windows to try the fallback legacy way of loading a commonjs module for Titanium modules (look for \"module-id.js\").", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2016-05-02T17:47:01.000+0000", "updated": "2016-05-02T17:47:01.000+0000" }, { "id": "386354", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "https://github.com/appcelerator/titanium_mobile_windows/pull/710", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2016-05-20T16:57:05.000+0000", "updated": "2016-05-20T16:57:05.000+0000" }, { "id": "389193", "author": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "body": "Verified using:\r\n\r\nWindows 10 Pro\r\nTi SDK: 5.4.0.v20160627150129\r\nAppc NPM: 4.2.7-2 \r\nAppc CLI: 5.4.0-18\r\nAppc Studio: 4.7.0.201606220541\r\n\r\nA CommonJS module that has no package.json or index.js can now be used, tested using the module from description https://github.com/Topener/To.ImageCache.\r\n\r\nClosing ticket.", "updateAuthor": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "created": "2016-06-27T23:53:57.000+0000", "updated": "2016-06-27T23:53:57.000+0000" } ], "maxResults": 9, "total": 9, "startAt": 0 } } }