How to resolve “TypeError: NetworkError when attempting to fetch resource.”

前端 未结 3 1081
小鲜肉
小鲜肉 2021-01-04 13:25

When I use aurelia-fetch-client to post json data to server and I got this error \"TypeError: NetworkError when attempting to fetch resource.\" I think your answer is very u

3条回答
  •  萌比男神i
    2021-01-04 14:16

    My feeling is that it may not be related to CORS. It may have to deal with the "import" mechanism(?) Here is my case: I got a "Source map error" message when I just updated my local version of OpenLayers to v5.0.0. Here is my html:

    
    
      
      
      
      Lignes SNCF
      
      
      
      
      
    
    
      

    Lignes SNCF

    and the error message:

    Source map error: TypeError: NetworkError when attempting to fetch resource.
    Resource URL: file:///E:/ENSEIGNEMENT/v5.0.0-dist/ol.js
    Source Map URL: ol.js.map[Learn More]
    

    Puzzlingly, the JavaScript code works correctly, and the map correctly displays on screen, even before the "Source map error" message on console.

    If I turn back to the previous version of OpenLayers, only difference:

    
    

    it works also, but with no error message.

    I do not see what to blame ... but Openlayers 5 is the first release intended to be used with "import ... from 'ol'". What I didn't try yet (other issues), I am still using:

    const map = new ol.Map(...);
    

    instead of:

    import Map from 'ol.Map.js';
    const map = new Map(...);
    

    I don't know what to blame, but the original question from "Suresh" has also something to do with the "import" mechanism. I my case I cannot see the point with CORS.

提交回复
热议问题