Javacript 3.23 bug with momentjs package?

1268
6
04-16-2018 08:36 AM
EricO_Neal1
New Contributor III

I'm attempting to use a 3rd party library in a WAB custom widget, and there is a dependency for momentjs.  Moment seems to be packaged with the ESRI Javascript API, but has a different definition for 'main' in init.js than the other packages (notice the .js on the end of it):  


}, {
location: "../xstyle",
name: "xstyle"
}, {
location: "../dgrid",
main: "OnDemandGrid",
name: "dgrid"
}, {
location: "../dgrid1",
main: "OnDemandGrid",
name: "dgrid1"
}, {
location: "../dstore",
main: "Store",
name: "dstore"
}, {
location: "../moment",
main: "moment.js",
name: "moment"
}, {
location: "../esri",
name: "esri"
}, {
location: ".",
name: "dojo"

When the define line is executed in the 3rd party library, it fails with:

GET https://js.arcgis.com/3.21/moment/moment.js.js net::ERR_ABORTED

It seems that the extra .js on moment in init.js is crapping things out and I notice that this has changed in JS API version 4.6.

0 Kudos
6 Replies
BalajiVeera
Occasional Contributor

Remove .js for moment in init.js

{
location: "../moment",
main: "moment",
name: "moment"
}

0 Kudos
EricO_Neal1
New Contributor III

I get that, but will need to download and host the JS API myself.  Cant fix it on the CDN.

0 Kudos
ReneRubalcava
Frequent Contributor

You should be able to override the dojoConfig for your WAB widget by with something like this

window.dojoConfig = {
  packages: [
    {
      location: "https://js.arcgis.com/3.<version>/moment/moment",
      main: "moment",
      name: "moment"
    }‍‍‍‍‍
  ]
}

Add the version of the API that the version of WAB using. You might need to check for an existing dojoConfig and make sure you don't override some current dojoConfig settings.

We'll get this fixed in 3.25

0 Kudos
EricO_Neal1
New Contributor III

I made the change that you siggested in both my Widget.js and my application's init.js and it now fails with:

GET https://js.arcgis.com/3.21/moment/main.js net::ERR_ABORTED

Not sure what main.js is or why its asking for it now.  I'm going to host  the API with my app and hack up it's init.js for now while developing.  I noticed that once the WAB application get built, the proper moment code seems to get updated (from WAB init.js):

if (window.apiUrl.substr(window.apiUrl.length - 'arcgis-js-api/'.length,
'arcgis-js-api/'.length) === 'arcgis-js-api/') {
//after build, we put js api here
//user can also download release api package and put here
dojoConfig.baseUrl = window.path;
}, {
name: "moment",
location: window.apiUrl + "moment"
}, {

Thanks,

Eric

0 Kudos
ReneRubalcava
Frequent Contributor

Correction, fixed in 3.24

EricO_Neal1
New Contributor III

Nice!

0 Kudos