Thanks Paul,
I'm using a similar version.
In one of the troubleshooting sessions, I modified the header of "moment.js" to the following:
;(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.moment = factory()
console.log("typeof(global): ", typeof(global));
global[ "one" ] = 1;
global[ "two" ] = 2;
global[ "three" ] = 3;
global[ "key" + Math.random() ] = 1;
console.log("global keys: ", JSON.stringify( Object.keys( global ) ) );
}(this, (function () { 'use strict';
Then in my app, I imported "moment.js" twice:
import "moment.js" as Moment1
import "moment.js" as Moment2
On the first import, this yielded the following output:
qml: typeof(global): object
qml: global keys: ["moment","one","two","three","key0.3286030239782699"]
On the second import, this yielded the following:
qml: typeof(global): object
qml: global keys: ["moment","one","two","three","key0.3286030239782699","key0.7088453144951244"]
i.e. what appears to be happening, is the value of "this" which later becomes "global" refers to Javascript object in the global namespace. What the moment.js library is trying to do is install a moment() as a function in the global namespace. For good measure, I wanted to see if I can put some random keys in the global namespace as well, and, yes, that appears to have worked too.
This means when you use these objects in your app, you don't need to use the specifier, i.e. I didn't use either Moment1 nor Moment2. I just referred to the moment() function directly.
Similarly, for the other items I added in the global namespace, I could access them too, e.g.
Text {
text: three
}
If you still cannot get it to work, then, yes, feel free to refer to my workaround, i.e.
var moment
;(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.moment = factory()
moment = global.moment
}(this, (function () { 'use strict';
Then, in your app, use the workaround as follows:
import QtQuick 2.7
import QtQuick.Controls 2.1
import ArcGIS.AppFramework 1.0
import "moment.js" as Moment
App {
id: app
width: 400
height: 640
property var moment: Moment.moment
Text {
text: moment().format("dddd")
}
}
Stephen