{ "id": "173485", "key": "AC-6219", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "8", "description": "", "name": "Needs more info" }, "resolutiondate": "2019-09-13T18:34:34.000+0000", "created": "2019-04-19T15:14:58.000+0000", "labels": [], "versions": [ { "id": "17038", "name": "Appcelerator Studio 4.5.0", "archived": false, "released": false } ], "issuelinks": [], "assignee": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2020-02-19T21:42:08.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "Since upgrading to SDK 8, any function referenced in a View is no longer found in the associated controller. \r\n\r\nFor example, in my mainview.xml I have the following\r\n\r\n\r\n\r\nand in the mainview.js I have\r\n\r\nfunction myFunction()\r\n{\r\n // Do Something\r\n}\r\n\r\nIn SDK7.5 this works fine, but in SDK8 I receive the error\r\n\r\n[ERROR] : Script Error {\r\n[ERROR] : column = 13;\r\n[ERROR] : line = 102;\r\n[ERROR] : message = \"Can't find variable: myFunction\";\r\n\r\nI have had this in previous SDK versions on occasions and SDK point releases then resolved the issue. I would like to move to SDK8 but until this is resolved, I will have to stay on 7.5 as I have a lot of functions reference in my XML views.\r\n\r\nBTW, this is impassible to replicate on a standalone project so may be linked to the size/complexity of the project perhaps....", "attachment": [], "flagged": false, "summary": "Runtime not finding function referenced within View", "creator": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "SDK 8 \r\nAxway Appcelerator Studio, build: 5.1.2.201903111843", "comment": { "comments": [ { "id": "447819", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This is something I cannot replicate as I think it's linked to the size and complexity of the code. I have had this issue with previous SDK versions and after a few point releases the issue goes.", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-04-21T16:42:07.000+0000", "updated": "2019-04-21T16:42:07.000+0000" }, { "id": "447839", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "[~developer@tpglobalpartners.com], when you build your app, do you see any \"BABEL\" warnings? I'm wondering if you're running into a transpile issue.\r\n\r\nDo a search for {{BABEL}} in your build log.\r\n\r\nFor example, I've seen the following BABEL warning happen in the past.\r\n{{exceeds the max of \"500KB\"}}\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-04-22T20:56:07.000+0000", "updated": "2019-04-22T20:56:07.000+0000" }, { "id": "447962", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Thanks for the suggestion, unfortunately no {{BABEL}} is in the build log, in fact there are no compilation errors at all. \r\n\r\nI turned off the Live View though and I received the following error, not sure if this is of any help\r\n\r\n[ERROR] : Script Error {\r\n[ERROR] : column = 13;\r\n[ERROR] : line = 102;\r\n[ERROR] : message = \"Can't find variable: myFunction\";\r\n[ERROR] : sourceURL = \"file:///Users/myuser/Library/Developer/CoreSimulator/Devices/699AE052-05D7-444F-BCFA-C6806B56C263/data/Containers/Bundle/Application/C8E83C3B-23E0-4823-81EF-074561834B38/myapp.app/alloy/controllers/myview.js\";\r\n[ERROR] : stack = \" at Controller(/alloy/controllers/myview.js:102:13)\\n at createController(/alloy.js:353:53)\\n at Controller(/alloy/controllers/index.js:41:49)\\n at createController(/alloy.js:353:53)\\n at (/app.js:165:23)\\n at global code(/app.js:167:70)\\n at require@[native code]\\n at require(/ti.internal/extensions/binding.js:21:25)\\n at (/ti.main.js:40:10)\\n at loadAsync(/ti.internal/bootstrap.loader.js:108:13)\\n at global code(/ti.main.js:37:52)\";\r\n[ERROR] : toJSON = \"\";\r\n[ERROR] : }\r\n[ERROR] : Script Error Module \"app.js\" failed to leave a valid exports object", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-04-25T17:57:39.000+0000", "updated": "2019-04-25T17:59:10.000+0000" }, { "id": "447966", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "[~developer@tpglobalpartners.com], do you have a function named {{myFunction()}} in your \"alloy.js\" file?\r\n\r\nBecause it sounds like your \"myview.js\" code is trying call {{myFunction()}} that I'm guessing exists in \"alloy.js\". If this is the case, then try adding {{myFunction()}} directly to the {{global}} object.\r\n\r\nFor example, if your \"alloy.js\" looks like the below...\r\n_(Doing the below in Titanium 8.0.0 will log an \"implicit global scope\" warning at runtime.)_\r\n{code:javascript}\r\nfunction myFunction() {\r\n\tconsole.log(\"Hello World\");\r\n}\r\n{code}\r\n\r\nThen do the following instead. The below will explicitly add the function to the global namespace. _(Note that it's a lowercase {{global}} which works in both Alloy and Classic Titanium apps.)_\r\n{code:javascript}\r\nglobal.myFunction = function() {\r\n\tconsole.log(\"Hello World\");\r\n}\r\n{code}\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-04-25T20:54:12.000+0000", "updated": "2019-04-25T20:54:12.000+0000" }, { "id": "447970", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Thanks for the update. \r\n\r\nThe myFunction referenced in the myview.xml is defined within the myview.js and the scope is contained within that. For some background info, I had this issue on a couple of point releases in SDK 6, it then went away and came back in SDK8, so not sure what the issue is.", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-04-26T09:06:38.000+0000", "updated": "2019-04-26T09:06:38.000+0000" }, { "id": "448057", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I can't reproduce this yet.\r\n\r\nTry this. Do a build and then go to the following directory...\r\n{{/Resources//alloy/controllers}}\r\n\r\nUnder the above directory, you should have {{myview.js}} file generated by the Alloy build system. Look for all references to your {{myFunction}} in that code. Something in there must be wrong. For example, double check that a copy of your function code exists in there. And you should see Alloy generated code in that file where it sets up a \"click\" listener with it via {{addListener()}}. Any clues you can find would be a big help.\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-04-29T22:49:42.000+0000", "updated": "2019-04-29T22:52:04.000+0000" }, { "id": "448264", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Check the file and it seems to be setting up the listener ok and the file looks the same between SDK7 and 8. With SDK8 though when it gives a runtime error \r\n\r\n[INFO] : [LiveView] Error Evaluating app.js @ Line: 65\r\n[ERROR] : ReferenceError: Can't find variable: myFunction\r\n[ERROR] : File: app.js\r\n[ERROR] : Line: 65\r\n[ERROR] : SourceId: \r\n[ERROR] : Backtrace:\r\n[ERROR] : undefined", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-05-09T17:06:20.000+0000", "updated": "2019-05-09T17:06:20.000+0000" }, { "id": "448969", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello, Let us know the current status of the issue. Please provide a reproducible sample code for us to test the issue if it is still reproducible with the latest SDK. Thanks.", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2019-06-10T23:44:40.000+0000", "updated": "2019-06-10T23:44:40.000+0000" }, { "id": "449089", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Same issue with the latest SDK. As mentioned, I cannot reproduce the test case, its an issue with some of the SDK versions and probably related to the size and complexity of the project. \r\n\r\nThe core issue is the same, when a function is referenced within a view and the associated controller contains the functuon definition, at runtime the function is not found on SDK8. I receive an error\r\n\r\nReferenceError: Can't find variable: myFunction\r\n\r\nOn SDK 7 it works fine.", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-06-14T17:55:54.000+0000", "updated": "2019-06-14T17:55:54.000+0000" }, { "id": "450023", "author": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "body": "[~developer@tpglobalpartners.com],\r\nDid you manage to test on 8.0.2.GA?We are looking forward to your response.", "updateAuthor": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2019-07-24T06:06:03.000+0000", "updated": "2019-07-24T06:06:03.000+0000" }, { "id": "450035", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Just tried this on 8.0.2.GA and the same issue - go back to 7.5.0 SDK and it works fine. ", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-07-24T14:38:22.000+0000", "updated": "2019-07-24T14:38:22.000+0000" }, { "id": "450037", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "Hello, We need a sample reproducible code, Can you please share your project that reproduces the issue? You can personally email us the project and we will look into it. Thanks.", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2019-07-24T15:28:23.000+0000", "updated": "2019-07-24T15:28:23.000+0000" }, { "id": "450038", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I will strip down the project to the barest minimum and send this to you, that would be best.", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-07-24T15:32:04.000+0000", "updated": "2019-07-24T15:32:04.000+0000" }, { "id": "450386", "author": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Hello,\r\nWe have not heard back from you since our last update. I just wanted to follow up with you about this issue? Are you still experiencing this problem?\r\n\r\nPlease let us know if you need more help with this issue.\r\n\r\n", "updateAuthor": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2019-08-12T05:20:22.000+0000", "updated": "2019-08-12T05:20:22.000+0000" }, { "id": "450807", "author": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Hello,\r\nJust passing as followup here. Are you able to get that sorted out? Please let us know if you need more help with this issue.\r\n\r\n", "updateAuthor": { "name": "rmitro", "key": "rmitro", "displayName": "Rakhi Mitro", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2019-08-25T11:01:22.000+0000", "updated": "2019-08-25T11:01:22.000+0000" }, { "id": "454306", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Came back to this as I needed to move to SDK and resolved the issue. It was due to the controller class have a try catch wrapper around the entire controller code which caused the issue. So if I had a controller called myPage.js with the following code:\r\n\r\ntry\r\n{\r\n function myFunction()\r\n {\r\n console.log(\"Hello World\");\r\n }\r\n}\r\ncatch ( e)\r\n{\r\n console.log(\"Error\");\r\n}\r\n\r\nand in the related view file I have\r\n\r\n\r\n\r\nIf in index.js I call \r\n\r\ntry\r\n{\r\n var newPage = Alloy.createController(\"myPage\");\r\n }\r\ncatch (e)\r\n{\r\n console.log (\"Error in index.js\");\r\n}\r\n\r\nthen I would receive a runtime error of \r\n\r\n{color:red}*[ERROR] :*{color} message = \"Can't find variable: myFunction\";\r\n\r\nSo to fix this, I removed the try-catch in myPage.js and then it would work no issues. This code however works in SDK7 as is, but fails in SDK8.", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-02-17T19:26:01.000+0000", "updated": "2020-02-17T19:29:04.000+0000" }, { "id": "454318", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I see. This sounds like a scoping issue. JavaScript \"functions\" are normally \"hoisted\" outside of their block scope like \"var\" declared variables.", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-02-18T19:08:06.000+0000", "updated": "2020-02-19T02:11:24.000+0000" }, { "id": "454326", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "After some extensive testing, I'm concluding this is a breaking-change in Google's V8 JavaScript runtime, because I can reproduce this same scoping/hoisting issue in node.js as well (which uses V8 like Titanium).\r\n\r\nFor example, the below throws an exception in node.js and Titanium. The below is the equivalent to what you are seeing in your Titanium project.\r\n{code:javascript}\r\nvar logMessageCallback = logMessage;\r\ntry {\r\n\tfunction logMessage() {\r\n\t\tconsole.log(\"@@@ Hello World\");\r\n\t}\r\n} catch (err) {\r\n\tconsole.log(err);\r\n}\r\nlogMessageCallback();\r\n{code}\r\n\r\nThe below works fine in node.js and Titanium. It hoists the function without issue.\r\n{code:javascript}\r\nvar logMessageCallback = logMessage;\r\nfunction logMessage() {\r\n\tconsole.log(\"@@@ Hello World\");\r\n}\r\nlogMessageCallback();\r\n{code}\r\n\r\nThe below works fine in node.js and Titanium as well. This proves hoisting works, but only after the function was defined.\r\n{code:javascript}\r\ntry {\r\n\tfunction logMessage() {\r\n\t\tconsole.log(\"@@@ Hello World\");\r\n\t}\r\n} catch (err) {\r\n\tconsole.log(err);\r\n}\r\nlogMessage();\r\n{code}\r\n\r\nAlso, wrapping the hoisted function like this doesn't work anyways. For example, try the below in node.js or Titanium. The exception cannot be caught because the {{logMessage()}} is really being declared outside of the try/catch block due to hoisting.\r\n{code:javascript}\r\ntry {\r\n\tfunction logMessage() {\r\n\t\tthrow new Error(\"@@@ Uh-Oh\");\r\n\t}\r\n} catch (err) {\r\n\t// You'll never get here.\r\n\tconsole.log('@@@ The exception was caught.');\r\n}\r\nlogMessage();\r\n{code}\r\n\r\nProbably the best solution is to move your try/catch inside of the callback functions you are trying to safeguard.\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-02-19T03:30:06.000+0000", "updated": "2020-02-19T03:35:13.000+0000" }, { "id": "454328", "author": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Ok this makes sense and what you have suggested is what I have done in the end for this to work. Thanks for the full diagnosis and assistance.", "updateAuthor": { "name": "developer@tpglobalpartners.com", "key": "developer@tpglobalpartners.com", "displayName": "Nigel Underwood", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-02-19T09:54:22.000+0000", "updated": "2020-02-19T09:54:22.000+0000" } ], "maxResults": 20, "total": 20, "startAt": 0 } } }