Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-24148

iOS: CommonJS modules/Library code cannot share names with native classes

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: Release 6.0.0
    • Fix Version/s: Release 6.0.1
    • Component/s: iOS
    • Labels:
    • Environment:

      MacOS 10.12 (16A323)
      Studio 4.8.0.201611121409
      Ti SDK 6.0.0.GA
      Appc NPM 4.2.8
      Appc CLI 6.0.0
      Alloy 1.9.4
      Xcode 8.1 (8B62)

      Description

      Creating a commonJS module or using library code files that share a name with internal native classes throws an error.

      [ERROR] :  Script Error {
      [ERROR] :  column = 24;
      [ERROR] :  line = 12;
      [ERROR] :  message = "undefined is not a function (evaluating 'util.test()')";
      [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";
      [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";
      [ERROR] :  }
      

      Steps to reproduce issue
      1. Create a new project
      2. Add a js file to the app/lib folder that has the name of an internal native class (utils.js, for example)
      3. Populate the file with an exported function
      4. Require the module in the index.js and call the exported function

      Expected Results
      The exported function is called without issue

      Actual Results
      The above error is thrown

      Code
      For the default Alloy project, change the index.js to:

      var foo = require('utils');
      function doClick(e) {
          alert(foo.test());
      }
       
      $.index.open();
      

      Then create a file called app/lib/utils.js (Alloy) or Resources/utils.js (Classic) and populate it with:

      exports.test = function() {
          return "I WAS CALLED";
      };
      

        Attachments

          Activity

            People

            • Assignee:
              hknoechel Hans Knöchel
              Reporter:
              ewieber Eric Wieber (Inactive)
              Reviewer:
              Christopher Williams
              Tester:
              Eric Wieber (Inactive)
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-10283
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration