Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24884] CLI: Minification produces invalid code

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2017-06-26T21:53:31.000+0000
Affected Version/sRelease 6.1.0
Fix Version/sRelease 6.1.1
Componentsn/a
Labelsn/a
ReporterEwan Harris
AssigneeChris Barber
Created2017-05-26T12:55:08.000+0000
Updated2017-11-07T10:56:19.000+0000

Description

Description

The titanium SDK minification process is causing the following apps to error out when building to iOS https://github.com/appcelerator/appc-university-app
[ERROR] Script Error {
[ERROR]     column = 697;
[ERROR]     line = 1;
[ERROR]     message = "Can't find variable: populateSpotlightSearch";
[ERROR]     sourceURL = "file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/9D8A7184-ABA4-47AE-BCBC-F3C4957D859D/University.app/alloy/controllers/index.js";
[ERROR]     stack = "file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/9D8A7184-ABA4-47AE-BCBC-F3C4957D859D/University.app/alloy/controllers/index.js:1:697\nonload@file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/9D8A7184-ABA4-47AE-BCBC-F3C4957D859D/University.app/appcelerator-university-service.js:1:1725";
[ERROR] }
https://github.com/appcelerator/movies
[ERROR] Script Error {
[ERROR]     column = 1680;
[ERROR]     line = 1;
[ERROR]     message = "Can't find variable: cellImageOffset";
[ERROR]     sourceURL = "file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/75763034-2C6D-473F-96AA-9110B270C2B3/Movies.app/alloy/controllers/movies_list.js";
[ERROR]     stack = "d@file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/75763034-2C6D-473F-96AA-9110B270C2B3/Movies.app/alloy/controllers/movies_list.js:1:1680\nfile:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/75763034-2C6D-473F-96AA-9110B270C2B3/Movies.app/alloy/controllers/movies_list.js:1:1343\nloadJsonFile@file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/75763034-2C6D-473F-96AA-9110B270C2B3/Movies.app/data.js:1:326\nmovies_get_list@file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/75763034-2C6D-473F-96AA-9110B270C2B3/Movies.app/data.js:1:548\nb@file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/75763034-2C6D-473F-96AA-9110B270C2B3/Movies.app/alloy/controllers/movies_list.js:1:1204\na@file:///Users/eharris/Library/Developer/CoreSimulator/Devices/DAE930F3-D384-42DE-B14D-F2EB6DDFE798/data/Containers/Bundle/Application/75763034-2C6D-473F-96AA-9110B270C2B3/Movies.app/alloy/controllers/movies_list.js:1:790";
[ERROR] }

Steps to reproduce

Obtain either of the above apps

Build with ti build -p ios --deploy-type test

* Movies, click one of the images * University app, just let the app load

Actual

Apps will error out

Expected

Apps should not error out

Comments

  1. Ewan Harris 2017-05-26

    This is fixed by applying the same fix in ALOY-1565, but I believe that probably isnt the fix we want to take as we will no longer be minifying fully https://github.com/appcelerator/node-titanium-sdk/pull/7
  2. Chris Barber 2017-05-26

    Alloy PR: https://github.com/appcelerator/alloy/pull/827
  3. Chris Barber 2017-05-26

    FYI, bug fix for the appc-university-app https://github.com/appcelerator/appc-university-app/pull/11
  4. Brenton House 2017-06-23

    [~cbarber] - I've tried the latest Alloy (1.10.3) w/ the RC build of 6.1.1 and we are still seeing an issue with how underscore.js is getting minified. It is causing an error when _.template is called. Is there a patch to Titanium as well as Alloy for this issue?
  5. Chris Barber 2017-06-23

    So, after this ticket's PR, Alloy no longer minifies. All minification is done in the TItanium SDK. The new minification process apparently shipped in 6.1.0.GA. Is there a chance you can whip up a small test case app and attach it to this ticket? That would really help.
  6. Brenton House 2017-06-23

    I have also tried with the latest SDK: 6.2.0.v20170622105148 underscore.js is still corrupted by the minification process.
  7. Brenton House 2017-06-23

    [~cbarber] - yes, I will create a test case and post it. I can also duplicate this by copying the underscore.js from the build folder and putting it in a node.js project and trying to use _.template as well.
  8. Brenton House 2017-06-23

    [~cbarber] -- Here is a simple project that duplicates the issue: https://github.com/brentonhouse/appc-minify-issue Just build this to an iOS device (with LiveView NOT enabled) to test it. The error you get is: {noformat} [ERROR] Script Error { [ERROR] column = 13811; [ERROR] line = 2; [ERROR] message = "Invalid escape in identifier: '\\'"; [ERROR] source = "var __t,__p=\\'\\',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,\\'\\');};\\nwith(obj||{}){\n__p+='\\n\\n '+\n((__t=( content ))==null?'':__t)+\n'\\n\\n';\n}\nreturn __p;\n"; [ERROR] sourceURL = "file:///var/containers/Bundle/Application/8C2018E6-AE2B-417F-B684-A172A3263407/appc-minify-issue.app/alloy/underscore.js"; [ERROR] } {noformat}
  9. Chris Barber 2017-06-23

    [~brentonhouse] Awesome! Thank you. I'll get started asap.
  10. Chris Barber 2017-06-23

    I tested your app with local builds of the Titanium SDK 6_1_X (6.1.1) and master (6.2.0) branches using Titanium CLI 5.0.14, Alloy 1.10.3, Xcode 8.3.3 (iOS 10.3.1), and Node.js 8.1.2 and it worked both times:
        -- Start simulator log -------------------------------------------------------
        [DEBUG] Reading stylesheet from: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/stylesheet.plist
        [INFO]  appc-minify-issue/1.0 (6.1.1.d36d308)
        [TRACE] [HYPERLOOP] willStartNewContext <KrollContext: 0x60800007b800>
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/app.js, Resource: app_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy, Resource: alloy
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy.js, Resource: alloy_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/underscore, Resource: alloy/underscore
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/underscore.js, Resource: alloy/underscore_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/backbone, Resource: alloy/backbone
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/backbone.js, Resource: alloy/backbone_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/underscore, Resource: alloy/underscore
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/underscore.js, Resource: alloy/underscore_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/constants, Resource: alloy/constants
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/constants.js, Resource: alloy/constants_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/underscore, Resource: alloy/underscore
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/underscore.js, Resource: alloy/underscore_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/CFG, Resource: alloy/CFG
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/CFG.js, Resource: alloy/CFG_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/controllers/index, Resource: alloy/controllers/index
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/controllers/index.js, Resource: alloy/controllers/index_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy, Resource: alloy
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy.js, Resource: alloy_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/controllers/BaseController, Resource: alloy/controllers/BaseController
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy/controllers/BaseController.js, Resource: alloy/controllers/BaseController_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy, Resource: alloy
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/alloy.js, Resource: alloy_js
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/_app_props_.json, Resource: _app_props__json
        [DEBUG] Loading: /Users/chris/Library/Developer/CoreSimulator/Devices/068C81B5-63C9-466B-BE58-D44C527736FF/data/Containers/Bundle/Application/0A4A83DE-7867-4343-B09C-59BA1951621B/appc-minify-issue.app/test.html, Resource: test_html
        [ERROR]
        [ERROR] <body>
        [ERROR]   This is a test
        [ERROR] </body>
        [DEBUG] Application booted in 134.616971 ms
        [TRACE] [HYPERLOOP] didStartNewContext <KrollContext: 0x60800007b800>
        -- End simulator log ---------------------------------------------------------
        
    It didn't seem to matter whether I used the JSCore framework or the built-in TiJSCore. I did NOT use Studio, LiveView, or the Appc CLI. Can you give me some more details about your environment?
  11. Brenton House 2017-06-23

    I tried with: Titanium SDKs 6.1.0.GA & 6.1.1.RC & 6.2.X Alloy 1.9.x and 1.10.3 OS: Mac OS X 10.12.5 Node.js: 6.10.3 npm: 3.10.10 Titanium CLI: 5.0.14 No Studio or LiveView. Did use Appc CLI 6.2.2 -(but I will try with Ti CLI next)- Same result with Ti CLI 5.0.14 I did upload the generated underscore.js file from the build folder here: https://raw.githubusercontent.com/brentonhouse/appc-minify-issue/master/underscore.min.js You can try to compare it to the underscore.js file in your build folder to see if it is different. You are building to a physical device, correct?
  12. Brenton House 2017-06-23

    For what it's worth, changing Titanium SDK to 6.0.4.GA (and no other changes) makes it work ok. Here is the minified underscore.js when using 6.0.4.GA: https://raw.githubusercontent.com/brentonhouse/appc-minify-issue/master/underscore.min_6.0.4.js
  13. Chris Barber 2017-06-23

    Oops, I was building for simulator. When I run ti build -p ios --deploy-type test, I can reproduce the error. Since I can reproduce the error in a Classic Titanium app, this is not an Alloy specific issue. I've reopened this ticket and moved it to TIMOB. Stay tuned.
  14. Brenton House 2017-06-23

    Thanks [~cbarber]!!
  15. Chris Barber 2017-06-23

    The problem is due to Babili double escaping single quotes. This logic is in node-titanium-sdk which has many out-of-date NPM dependencies. I updated the NPM deps and the error goes away. I will update node-titanium-sdk's deps and get a new version published, then we can update TiSDK master and 6_1_X.
  16. Chris Barber 2017-06-23

    node-titanium-sdk PR: https://github.com/appcelerator/node-titanium-sdk/pull/9
  17. Chris Barber 2017-06-23

    TiSDK master PR: https://github.com/appcelerator/titanium_mobile/pull/9176 TiSDK 6_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/9177 To test, create a classic Titanium app, drop underscore.js in the Resources directory, then add this to the app.js:
        var _ = require('underscore');
        var template = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + 'test.html').read().getText();
        var data = { content: 'This is a test' };
        var text = _.template(template)(data);
        console.error(text);
        
  18. Abir Mukherjee 2017-06-26

    Passed FR. Node Version: 6.10.3 NPM Version: 3.10.10 Mac OS: 10.12.4 Appc CLI: 6.2.2 Appc CLI NPM: 4.2.9 Titanium SDK version: 6.1.X locally built w/ pr/9177 Appcelerator Studio, build: 4.9.0.201705302345 Xcode 8.3.2 iOS Device 10 I tried the demo apps and there were no errors when launched. For the "movies" app I also pushed a button. No errors were seen, and a list of movies were shown. Closing ticket as changes were seen in 6.1.1.v20170626160851
  19. Hans Knöchel 2017-09-21

    Regression triggered by this ticket: TIMOB-25328

JSON Source