Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10491] iOS: Changes to how iOS does require in 2.2 have broken require

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-12-21T05:25:09.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sSprint 2012-17 Core, Release 3.0.0
ComponentsiOS
Labelscore, module_require, qe-review, qe-testadded, regression
ReporterRussell McMahon
AssigneeMax Stepanov
Created2012-08-17T19:00:27.000+0000
Updated2012-12-21T05:25:09.000+0000

Description

When running Alloy on iOS 2.2.0 master the alloy.js commonjs module can not be found. It is required in as require('alloy') other modules are loading okay. The path to alloy.js is Resources/alloy.js there is also a folder alloy.

Comments

  1. Tony Lukasavage 2012-08-21

    Here's a minimal test case that is *NOT* alloy specific. The name alloy is used for the modules and it uses a similar structure, but this is pure Titanium code. These following three files do not require Alloy to show the following error: {quote} [ERROR] Script Error = Couldn't find module: alloy 2012-08-21 19:05:31.125 testRequireBug[28934:1a70b] *** Terminating app due to uncaught exception of class '__NSCFString' terminate called throwing an exception [INFO] Application has exited from Simulator {quote}

    Test Case

    app.js

       require('alloy').getController('index');
       

    alloy.js

       exports.getController = function(name, args) {
           return new (require("alloy/controllers/" + name))(args); 
       }
       

    alloy/controllers/index.js

       var Alloy = require('alloy'); // commenting this line avoids the error
       module.exports = function Controller() {};
       
  2. Tony Lukasavage 2012-08-21

    It is also worth nothing that Alloy works fine with the lastest TiSDK 2.2.0 with Android and Mobileweb. Alloy actually worked with iOS on 2.2.0 up until about a week or two ago.
  3. Russell McMahon 2012-08-21

    Looking at the code with Blain it appears that perhaps the commonjs spec may not have been followed as intended in the latest iOS code. Please see #4, #5 below as it talks about top level modules: CommonJS 1.1 Spec - Module Identifiers 1) A module identifier is a String of "terms" delimited by forward slashes. 2) A term must be a camelCase identifier, ".", or "..". 3) Module identifiers may not have file-name extensions like ".js". 4) Module identifiers may be "relative" or "top-level". A module identifier is "relative" if the first term is "." or "..". 5) Top-level identifiers are resolved off the conceptual module name space root. 6) Relative identifiers are resolved relative to the identifier of the module in which "require" is written and called.
  4. Max Stepanov 2012-08-22

    PR pending https://github.com/appcelerator/titanium_mobile/pull/2806
  5. Blain Hamon 2012-08-23

    Pull merged.
  6. Satyam Sekhri 2012-08-28

    No error shown when tested by creating a titanium app and module named alloy Verified on: Titanium Studio: 2.1.2.201208201549 Titanium SDK: 2.2.0.v20120827143312 iPhone Simulator (v5.1)

JSON Source