Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11408] Android: Runtime error is thrown for require method when called from window opened via URL

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-01-29T23:37:31.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.0.0, Release 3.1.0, 2012 Sprint 22 Core, 2012 Sprint 22, 2013 Sprint 03 API
ComponentsAndroid
Labelscore, qe-and100112, qe-port, regression
ReporterShyam Bhadauria
AssigneePing Wang
Created2012-10-12T09:05:32.000+0000
Updated2013-02-04T07:14:20.000+0000

Description

This is a regression. It works fine on 2.1.3GA. When the app is run, a runtime error is thrown - "Message: Uncaught ReferenceError: require is not defined". Log attached. Steps to reproduce: 1. Use the following code in app.js
Ti.UI.createWindow({
	url: "win.js", // causes new JS context
	backgroundColor: "#000",
	exitOnClose: true
}).open();
2. Create a file 'included.js' under 'Resources' folder and add the code below in it-
var includedWord = "YES";
3. Create another file win.js under 'Resources' folder and add the code below in it-
require("module"); // Don't need return value, just important that this runs.
Ti.include("included.js");
alert("Does this app work (YES/NO)? \nAnswer: " + includedWord);
4. Paste the attached file 'module.js' under the 'Resources' folder. 5. Run the app on android device. Expected result: App should display an alert 'Does this app work? YES!' Actual result: A runtime error is thrown. Error log attached.

Attachments

FileDateSize
module.js2012-10-25T10:25:44.000+000042
TIMOB 5434.rtf2012-10-12T09:05:32.000+00001112

Comments

  1. Josh Roesslein 2012-10-16

    Created [PR #3244 ](https://github.com/appcelerator/titanium_mobile/pull/3244) to resolve issue on master.
  2. Bill Dawson 2012-10-16

    Master merge done. Ready for 3.0.X PR. *Note for future testers*: The person who created the ticket didn#t include module.js, so success in this case actually means getting an error that the module is not found, as opposed to the error that require is not defined.
  3. Josh Roesslein 2012-10-16

    Created [PR #3252](https://github.com/appcelerator/titanium_mobile/pull/3252) to back port fix into 3_0_X.
  4. Bill Dawson 2012-10-16

    3_0_X PR merged.
  5. Shyam Bhadauria 2012-10-25

    Please use the module.js attached (module_timob5434) to reproduce the issue along with other files.It still gives same error 'Message: Uncaught ReferenceError: require is not defined'. Tested it with : Titanium SDK:3.0.0.v20121024144610 Titanium  Studio:3.0.0.201210220122
  6. Allen Yeung 2012-10-30

    This should as a part of this PR: https://github.com/appcelerator/titanium_mobile/pull/3321
  7. Shyam Bhadauria 2012-11-20

    Its working fine now. Titanium SDK: 3.1.0.v20121119222601 Titanium SDK:3.0.0.v20121113170203 Titanium  Studio:3.0.0.201211131839 Device : Android 2.2 LG-P970 Xcode : 4.5 Machine OS : MAC 10.8
  8. Ping Wang 2013-01-29

    This issue occurs again in the latest 3_0_X build: ffb007d573b779957baebb82895f7bf0b0f60d32
  9. Ping Wang 2013-01-29

    This regression is caused by [PR#3321](https://github.com/appcelerator/titanium_mobile/pull/3321) PR: https://github.com/appcelerator/titanium_mobile/pull/3818 For FR: 1. Run the test case in the ticket. It should run without any crash. 2. Run the test case below. It should run without any crash. The log should show: {quote} I/TiAPI (13592): ******************** module.text = I'm module I/TiAPI (13592): ******************** module.includedWord = YES I/TiAPI (13592): *************** inside module.x {quote} app.js
       Ti.UI.createWindow({
           url: "win.js", // causes new JS context
           backgroundColor: "#000",
           exitOnClose: true
       }).open();
       
    win.js
       var module = require("module");
       Ti.API.info("******************** module.text = " + module.text);
       Ti.API.info("******************** module.includedWord = " + module.includedWord);
       module.x();
       
       Ti.include("included.js");
       alert("Does this app work (YES/NO)? \nAnswer: " + includedWord);
       
    module.js
       exports.x = function() {
       	console.log("*************** inside module.x");
       };
       exports.text = "I'm module";
       
       Ti.include("included.js");
       exports.includedWord = includedWord;
       
    included.js
       var includedWord = "YES";
       
    3. Run the test cases in TIMOB-10783, TIMOB-10091, TIMOB-11307, TIMOB-5748. 4. Run KS. 5. Run Anvil -> includes/includes test suite. simpleRequire, secondContextRequire, multipleRequire and includeFromUrlWindow should pass.
  10. Anshu Mittal 2013-02-04

    Tested with: SDK:3.0.2.v20130201161712 Studio: 3.0.2.201301281948 Device: iPhone3GS(v 5.0.1), iPhone5(v 6.0) No runtime error is thrown.

JSON Source