Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1624] Alloy: moment is not a function. (In 'moment(myDate)', 'moment' is an instance of Object)

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterAlberto Marcone
AssigneeShak Hossain
Created2018-07-12T17:17:04.000+0000
Updated2019-08-20T21:07:59.000+0000

Description

When I try to use moment, like I always did:
var moment = require('/alloy/moment');
var date = moment(myDate).format('DD/MM/YYYY - HH:mm');
I get the error from the title: moment is not a function. (In 'moment(myDate)', 'moment' is an instance of Object) where moment is actually an object:
 {
       id = "alloy/moment.js";
       uri = "app://alloy/moment.js";
  }

Comments

  1. Rene Pot 2018-07-16

    Hi [~a.marcone], just checked myself with 7.2.0.GA with the code you provided and it seems to be working. Are you overriding moment in your app anywhere?
  2. Alberto Marcone 2018-07-18

    Hi, moment is not overridden anywhere. I just noticed that I get the same error with other alloy libraries:
    var animation = require('alloy/animation');
       [INFO] :   animation :  {
       [INFO] :       id = "alloy/animation.js";
       [INFO] :       uri = "app://alloy/animation.js";
       [INFO] :   }
       
    this doesn't happen on an empty project indeed. Not sure where to look for, any idea?
  3. Feon Sua Xin Miao 2018-07-18

    [~topener], [~a.marcone], I can't reproduce either on both iOS and Android. SDK 7.2.0.GA and CLI 7.0.4. [~a.marcone] 1. Does this only happen to requiring alloy builtins? 2. Does require not work for both iOS and Android for you? 3. Which SDK works/worked for you? It will help greatly if you could upload an app that we can use to reproduce the issue.
  4. Alberto Marcone 2018-07-19

    We tested it on 3 different workstations, it works on one (where the project was initially developed - linux) but it doesn't work on other two ( linux - mac). This happens on either Android or iOS. The projects are checked out from our repository in the same way, there are no differences. It's not a matter of SDK because it works with the same SDK on one workstation but it doesn't on another. This happens only with the alloy builtins, we have other commonjs libs in the lib/ folder and they work as expected. We can't reproduce the same problem with another mock project because, as noted above, it only happens with this project. At this point we're not asking for a complete solution, just if you give us enough pointers to understand where to look at during the alloy requiring. Thank you very much
  5. Hans Knöchel 2018-07-19

    Can you send a copy of your project (confidential of course) to our core team via hknoechel@axway.com? We will then try to reproduce and check if we can fix up the project.
  6. Aleksey Gureiev 2018-09-10

    This also happens to our project sporadically. I discovered that when it happens, build/iphone/assets/alloy/moment_js and .../dialogs_js are completely empty. However widget_js and underscore_js are alright. Hope it helps. I seem can't find how to make it work again. It just restores itself after a couple of times removing build, app, and platform folders. Sometimes I even reinstall all node_modules.
  7. Nirmal 2019-06-05

    This usually happens after an attempt to build has failed with a compiler error. Subsequent builds will throw this runtime error not able to find built-in library - in my case moment. Resetting the build cache using appc clean makes this error go away.
  8. Nikita Radaev 2019-08-20

    Leaving a comment in case this ever gets solved.

JSON Source