Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9860] iOS: require ('abc/xyz') and require('/abc/xyz') get treated differently

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-07-16T11:04:29.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 3.0.0
ComponentsiOS
LabelsSupportTeam, core, module_require, parity, qe-testadded
ReporterVarun Joshi
AssigneeNeeraj Gupta
Created2012-07-02T14:13:04.000+0000
Updated2013-07-16T11:04:29.000+0000

Description

Problem

The javascript path argument for "required" with and without a slash in the beginning get treated as a whole new class. var xyz1 = require ('/abc/xyz'); // gets loaded var xyz2 = require ('/abc/xyz'); // won't loaded again var xyz3 = require ('abc/xyz'); // will loaded again since the path doesn't start with a slash although it's pointing to the same javascript file.

Steps to Reproduce

Run the sample code below and put a breakpoint or a debug statement to see the loading of require statement {noformat} // MyClass.js var instance = null; exports.getInstance = function() { if (instance == null) { instance = new MyClass(); } return instance; } {noformat} **app.js** {noformat} var xyz1 = require('/MyClass'); var xyz2 = require('/MyClass'); var xyz3 = require('MyClass'); {noformat} If the file has been loaded already, the "instance" should NOT be null.

Comments

  1. Ivan Skugor 2012-07-03

    According to CommonJs specification, leading slash should not be present and it is not valid module id: http://wiki.commonjs.org/wiki/Modules/1.1 Leading slash is working on some platforms in Titanium and many people use it, but nevertheless it shouldn't work because it's against specification. So, this issue is actually invalid.
  2. Stephen Tramer 2012-07-03

    Should be resolved by pull request for TIMOB-9524.
  3. Blain Hamon 2012-07-13

    Pull#2414 merged.
  4. Stephen Tramer 2012-07-16

    Depending on the result of commonjs compliance this fix may be removed.
  5. Satyam Sekhri 2012-08-30

    Path with or without slash are not treated differently in require. Verified on: Titanium Studio: 2.1.2.201208281351 Titanium SDK: 2.2.0.v20120828153312 iOS Simulator v5.1
  6. Priya Agarwal 2013-07-16

    Reopening to update label.
  7. Priya Agarwal 2013-07-16

    Updated label. Verified with: Titanium Studio:3.1.2.201307091843 Titanium SDK: 3.1.2.v20130710144553 acs:1.0.3 alloy:1.1.3 npm:1.2.14 titanium:3.1.1 titanium-code-processor:1.0.1 OS: OSX 10.8 Device: Galaxy Nexus (v4.0.4),iphone4(v5.1) Xcode: 4.5.1 Path with or without slash are not treated differently in require.

JSON Source