Titanium JIRA Archive
Appcelerator Community (AC)

[AC-487] Alloy fails to properly include Common JS modules

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionCannot Reproduce
Resolution Date2015-11-05T06:29:48.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterTim Poulsen
AssigneeMotiur Rahman
Created2015-11-04T01:25:17.000+0000
Updated2015-11-05T06:29:48.000+0000

Description

Ever since roughly version 1.5.1, Alloy has had problems with Common JS modules. It appears to be related to re-requiring in a library, as you might do if you require the module within a function. The app will throw a red-screen-o-death error that undefined has no such methods.
function doFoobar() {
   var foo = require('foolib');
   foo.bar();
}

doFoobar(); // might work once
doFoobar(); // most most certainly it will throw the second time
I tried again with Alloy 1.7.23 today and got the same error. Using the exact same code, switching back to Alloy 1.5.1 and the app works without error.

Comments

  1. Sharif AbuDarda 2015-11-04

    Hello, This isn't a valid bug. I tried to reproduce this with alloy 1.6.2. The common JS module works. index.js
       function doClick(e) {
           var foo = require('common');
           var data = new foo(); 
           }
       
       $.index.open();
       
    common.js
       function common() {
           return alert ("You clicked the button");
       };
       module.exports = common;
       
    index.xml
       <Alloy>
       	<Window class="container">
       		<Label id="label" onClick="doClick">Hello, World</Label>
       	</Window>
       </Alloy>
       
    Thanks.
  2. Tim Poulsen 2015-11-04

    I run into this bug frequently in actual applications. Yet I am unable to create a simple test case app that demonstrates it. I have two apps currently with which I have to use Alloy 1.5.1 because they fail if built with anything newer. As stated, simply downgrading to 1.5.1 "fixes" the issue. I suspect the minification / uglification process of Alloy is dropping a declaration that it thinks is a duplicate. Perhaps it happens only with sufficiently complex apps.

JSON Source