[ALOY-1624] Alloy: moment is not a function. (In 'moment(myDate)', 'moment' is an instance of Object)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Alberto Marcone |
Assignee | Shak Hossain |
Created | 2018-07-12T17:17:04.000+0000 |
Updated | 2019-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";
}
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?
Hi, moment is not overridden anywhere. I just noticed that I get the same error with other alloy libraries:
this doesn't happen on an empty project indeed. Not sure where to look for, any idea?
[~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. Doesrequire
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.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
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.
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. Howeverwidget_js
andunderscore_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.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.Leaving a comment in case this ever gets solved.