Moment Library not loading correctly

1251
4
02-03-2022 07:17 AM
Labels (2)
JustinBridwell2
Occasional Contributor II

I am working on a Web AppBuilder application that uses 3rd party libraries. One of these libraries includes the Moment and Moment-Timezone libraries. On load, I immediately get and error: 'Uncaught TypeError: Cannot read properties of undefined (reading 'tz')'. Researching this; I found an article that point to the source of this problem being due to the moment-timezone-with-data-min.js file loading before the moment-min.js file. I am not sure where to make this change within my app. It looks like the libs get loaded as resources in my `init.js` file and I have placed them in the proper order there. Is there another folder or file with dependencies? I also see that in the libs folder, there is a moment folder and the files are in this order. How can I change this order so they load properly. Or is there another issue I may be overlooking?

Moment.PNG

0 Kudos
4 Replies
LaurynasGedminas2
Occasional Contributor
JustinBridwell2
Occasional Contributor II

In what file do you propose adding the above code? The main widget.js? If so, I am using WabVersion 2.20, and I don't see any 'require'. I do have 'define(['<path to libs>'], function(<lib_name>) {<code goes here>});' in my widget.js file? Is there another file I would add that to? I already have it in my main init.js file as mentioned, but that does not seem to guarantee it gets loaded in the proper order:

From init.js:

    

resources = resources.concat([
      window.apiUrl + 'dojo/resources/dojo.css',
      window.apiUrl + 'dijit/themes/claro/claro.css',
      window.apiUrl + 'esri/css/esri.css',
      window.path + 'jimu.js/css/jimu-theme.css',
      window.path + 'libs/moment/moment.min.js',
      window.path + 'libs/moment/twix.js',
      window.path + 'libs/moment/moment-timezone-with-data.min.js',

    ])

0 Kudos
LaurynasGedminas2
Occasional Contributor

Yes, in the Widget.js file:

LaurynasGedminas2_0-1644425710912.png

 

JustinBridwell2
Occasional Contributor II

OK, just to clarify; Should I add that `require({ paths: { moment: '<path to moment>}});` at the top and then add it underneath in my `define({'moment'}), as well?

0 Kudos