ES Modules (v4.19) throwing CORS errors

3044
10
Jump to solution
05-03-2021 01:31 PM
by Anonymous User
Not applicable

Hello,

I have been using the JavaScript api in an angular app since 4.17, I was able to work with TypeScript and the builds are working fine with WebPack, when 4.18 became available, I decided to ditch our reliance on the WebPack scripts that were being used, and went with the 'supported' method of copying the assets and referencing them via esriConfig.assetsPath, That was working great after some trial and error, and now that 4.19 is out and 'production ready' we wanted to move away from the reliance of having to deploy all the assets with the web app (deployed to containers, so an extra ~20MB per deploy would be good to get rid of).

I removed the line that was setting the assets path, removed the copy of assets locally and updated the reference to the CSS stylesheet. all is _almost_ well; the app loads, requests are made to the assets, paths are correct, BUT I am getting CORS errors from the ESRI servers when trying to load the assets (js.arcgis.com)? I can manually navigate to the links just fine, so I know the paths are correct, but the webmap won't load any esri widgets, all my custom code is working fine, Portal items are loaded and display, but any request to the javascript assets fail with the CORS error (just one example):

Spoiler
Access to fetch at 'https://js.arcgis.com/4.19/@arcgis/core/assets/esri/widgets/LayerList/t9n/LayerList.json' from origin 'https://EXTERNAL-URL.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Fonts and CSS from the CDN work just fine (main.css, icon for basemap widget, font file all get sent down fine).

I can go back to using the local assets, but since that is ~20MB, I would really like to avoid having to depend on it to make the maps work. Thanks for any help!

0 Kudos
10 Replies
by Anonymous User
Not applicable

Yes, we are using interceptors that are adding headers (azure-msal-angular). it looks like I can modify one of them to ignore calls to js.arcgis.com (the one using Okta - will need to test a bit more to verify), but it looks like the other one I may end up having to rely on the local assets. Thanks for the insight and help with this!

0 Kudos