[AC-487] Alloy fails to properly include Common JS modules
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Resolved |
| Resolution | Cannot Reproduce |
| Resolution Date | 2015-11-05T06:29:48.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | n/a |
| Labels | n/a |
| Reporter | Tim Poulsen |
| Assignee | Motiur Rahman |
| Created | 2015-11-04T01:25:17.000+0000 |
| Updated | 2015-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.
Hello, This isn't a valid bug. I tried to reproduce this with alloy 1.6.2. The common JS module works. index.js
common.jsfunction doClick(e) { var foo = require('common'); var data = new foo(); } $.index.open();index.xmlfunction common() { return alert ("You clicked the button"); }; module.exports = common;Thanks.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.