Titanium JIRA Archive
Appcelerator Community (AC)

[AC-200] iOS: Using buildin moment.js case uncaught exception

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2015-08-05T08:11:56.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterEthan Chen
AssigneeRadamantis Torres-Lechuga
Created2015-07-07T02:03:24.000+0000
Updated2015-08-19T17:49:16.000+0000

Description

I'm using buildin moment.js with locale zh-Hant, but I got a uncaught exception and exit the app automatically.
/alloy/moment/lang/zh-Hant.js, Resource: alloy/moment/lang/zh-Hant_js
Uncaught exception: Couldn't find module: alloy/moment/lang/zh-Hant for architecture: i386
Controller:
var moment = require('alloy/moment');
console.log(moment.version)
even though I use a moment + locales.js from [official site](http://momentjs.com/) and put the file moment.js on lib, same problem just happened:
var moment = require('moment');
moment.locale('en-US');    // exception
moment.locale('en-us');    // exception
moment.locale('zh-TW');    // exception
moment.locale('zh-tw');    // exception
moment.locale('zh-CN');    // exception
moment.locale('zh-cn');    // exception
moment.locale('en');        // working fine

Comments

  1. Motiur Rahman 2015-07-07

    Hello, We did not reproduce this issue when we use Alloy.builtins.moment we get this following
       var moment = require('alloy/moment');
       console.log(moment.version)
       
    *Output*
       [INFO] :   2.7.0
       
    When we use moment + locales.js from [official site](http://momentjs.com/) and put the file on Assets folder and the result, is
       var moment = require('moment-with-locales');
       console.log(moment.locale('en-US'));   
       console.log(moment.locale('en-us'));    
       console.log(moment.locale('zh-TW'));    
       console.log(moment.locale('zh-tw'));    
       console.log(moment.locale('zh-CN'));   
       console.log(moment.locale('zh-cn'));    
       console.log(moment.locale('en'));     
       
    *Output*
       [INFO] :   en
       [INFO] :   en
       [INFO] :   zh-tw
       [INFO] :   zh-tw
       [INFO] :   zh-cn
       [INFO] :   zh-cn
       [INFO] :   en
       
    We did not get any exception. Thanks
  2. Ethan Chen 2015-07-08

    In the [document](http://docs.appcelerator.com/platform/latest/#!/guide/Alloy_Controllers) it says: {quote} Some JavaScript code might not be suitable as controller code, since it does not have an associated view, or you want to separate it from the MVC framework for easier reusability. Create a folder called lib in the app directory of your Alloy project. Add your CommonJS modules or JavaScript code using the CommonJS format into the lib folder. These files are copied to the Resources folder, when compiling your Alloy project. {quote} so I put my moment.js into app/lib, but still got exception bq.
    Couldn'y find module: ./locale/en-US for architecture: i386
  3. Ethan Chen 2015-07-08

    I try putting the moment.js in app/assets folder, same test code, same exceptions, same crushes.
       [ERROR] :  The application has crashed with an uncaught exception 'org.test.kroll'.
       [ERROR] :  Reason:
       [ERROR] :  Couldn't find module: ./locale/en-US for architecture: i386
       [ERROR] :  Stack trace:
       [ERROR] :  
       [ERROR] :  0   CoreFoundation                      0x04f7e72a __exceptionPreprocess + 154
       [ERROR] :  1   libobjc.A.dylib                     0x04b51a97 objc_exception_throw + 44
       [ERROR] :  2   test                                0x00024550 -[KrollBridge require:path:] + 4496
       [ERROR] :  3   test                                0x0002d1b6 CommonJSRequireCallback + 230
       [ERROR] :  4   test                                0x0039fe9a _ZN2TI19APICallbackFunction4callINS_18JSCallbackFunctionEEExPNS_9ExecStateE + 698
       [ERROR] :  5   test                                0x0037ae86 _ZN2TI14handleHostCallEPNS_9ExecStateENS_7TiValueENS_22CodeSpecializationKindE + 630
       [ERROR] :  6   test                                0x0037b25c linkFor + 156
       [ERROR] :  7   test                                0x003758d9 operationLinkCall + 25
       [ERROR] :  8   ???                                 0x503c9134 0x0 + 1346146612
       [ERROR] :  
       [ERROR] :  2015-07-08 10:33:19.545 test[20774:4690187] *** Terminating app due to uncaught exception 'org.test.kroll', reason: 'Couldn't find module: ./locale/en-US for architecture: i386'
       [ERROR] :  *** First throw call stack:
       [ERROR] :  (
       [ERROR] :  	0   CoreFoundation                      0x04f7e746 __exceptionPreprocess + 182
       [ERROR] :  	1   libobjc.A.dylib                     0x04b51a97 objc_exception_throw + 44
       [ERROR] :  	2   test                                0x00024550 -[KrollBridge require:path:] + 4496
       [ERROR] :  	3   test                                0x0002d1b6 CommonJSRequireCallback + 230
       [ERROR] :  	4   test                                0x0039fe9a _ZN2TI19APICallbackFunction4callINS_18JSCallbackFunctionEEExPNS_9ExecStateE + 698
       [ERROR] :  	5   test                                0x0037ae86 _ZN2TI14handleHostCallEPNS_9ExecStateENS_7TiValueENS_22CodeSpecializationKindE + 630
       [ERROR] :  	6   test                                0x0037b25c linkFor + 156
       [ERROR] :  	7   test                                0x003758d9 operationLinkCall + 25
       [ERROR] :  	8   ???                                 0x503c9134 0x0 + 1346146612
       [ERROR] :  )
       [ERROR] :  libc++abi.dylib: terminating with uncaught exception of type NSException
       
  4. Motiur Rahman 2015-07-23

    Hello [~ethancfchen], Please test with latest Studio 4.1.1 and SDK 4.1.0 and let us know. Thanks.
  5. Manuel Conde Vendrell 2015-08-19

    Hi. I was able to made it work as @Motiur explained with Ti 4.1.1 (getting moment-with-locales and putting it in assets), but I have one question: Is this the new way to use localized moments? In Ti3.5.0GA the translations worked alone, you only need to set the format and moment get the current device language alone. Why this changed in 4.1.1?

JSON Source