0

I would like to build my angular application with the cross origin build option. I am currently using a couple of build options and it works fine (prod and output-hashing). When I attempt to add cross-origin build option in the command line I get the following error: Unknown option --cross-origin (or --crossOrigin depending on how I write it so it is not a case convention issue). If add the the crossOrigin option to the angular.json file under the projects architect build options section then I get the following error: Schema validation failed with the following errors: Data path "" should NOT have additional properties(crossOrigin). I would like to know what is causing this error and how to overcome it.

David Sagang
  • 317
  • 1
  • 6
  • 24
  • Why.... do you think this is even an option..? And what do you expect it to do..? – MikeOne Jul 31 '20 at 16:23
  • @MikeOne it will allow you to set the different values of your cross origin options https://angular.io/cli/build#options. – David Sagang Jul 31 '20 at 16:28
  • Right, never heard of that one . So this will only fix very specific scenario’s right (https://stackoverflow.com/questions/18336789/purpose-of-the-crossorigin-attribute)? What Angular version are you using? – MikeOne Jul 31 '20 at 16:37
  • Angular version 7 – David Sagang Jul 31 '20 at 16:57
  • Right.. it seems that option flag was added in v8.1.. – MikeOne Jul 31 '20 at 17:00
  • Do we have any evidence for that? How do we manipulate CORS behavior in Angular now? – David Sagang Jul 31 '20 at 17:05
  • What exactly do you want? This will not fix cors issues with the http client.. (see SO link I posted earlier). Evidence: https://github.com/angular/angular-cli/issues/14743 – MikeOne Jul 31 '20 at 17:07
  • I have ajax calls that are working in IE but are throwing CORS errors in Chrome. I am using Windows authentication. – David Sagang Jul 31 '20 at 17:15
  • Rule of thumb.. CORS issues can ONLY be solved server side. Does the server return CORS headers? – MikeOne Jul 31 '20 at 17:18
  • If it works in IE that means the server setting as it relates to CORS is correct. The issue here is the harsh Chrome security restriction. – David Sagang Jul 31 '20 at 17:20
  • Chrome is fine really. IE’s CORS implementation is broken in some versions. Can you show the headers returned? And the exact error you’re seeing? – MikeOne Jul 31 '20 at 17:22
  • Access to XMLHttpRequest at 'web url1' from origin 'web url 2' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. – David Sagang Jul 31 '20 at 17:25
  • Chrome prompts for credentials when IE does not. – David Sagang Jul 31 '20 at 17:25
  • The error is pretty clear..? Bottom line, there is nothing you can do in Angular to fix a CORS issue (unless the issue is related to something like an unexpected redirect or something). Your server needs to respond with the correct headers. – MikeOne Jul 31 '20 at 17:29
  • My point is the same server responds to IE, and I build an aspx page with JQuery that responds to Chrome fine. – David Sagang Jul 31 '20 at 17:31
  • Yeah.. that doesn’t sounds like cross origin. I don’t hink I can help you any further. Good luck with this. – MikeOne Jul 31 '20 at 17:37
  • The `crossOrigin` option is somewhat niche (in terms of what it applies to) from what I understand. For people to further help, please add some info on how you send the requests (and maybe an example of the request and response headers, also in comparison to those jquery requests you mentioned). – Gunnar B. Jul 31 '20 at 17:46
  • @GunnarB I am just making a GET ajax call. It works in IE but I have the above mentioned CORS issue in Chrome. – David Sagang Jul 31 '20 at 19:20

0 Answers0