This question already has an answer here:

I'm using OSM Standard base layer with Openlayer V4.1 API. While accessing OSM getting Exception:

Access to Image at 'https://b.tile.openstreetmap.org/18/113126/107324.png' from origin 'http://localhost:9040' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9040' is therefore not allowed access. The response had HTTP status code 404.

I also tried with and Without crossOrigin null. The code is:

map = new ol.Map({
      layers: [
        new ol.layer.Tile({
          source: new ol.source.OSM(),
          opacity: 0.7,
      target: 'map',
      view: new ol.View({
        center: [19412406.33, -5050500.21],
        zoom: 5

Any help to solve the issue?

marked as duplicate by Jochen Schwarze, nmtoken, ArMoraer, IvanSanchez, JGH Aug 13 '18 at 16:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Could you please tell me if it's duplicate then where i will enable CORS or put jar files etc. for OpenStreetMap.Because that duplicate refrence link question gis.stackexchange.com/questions/113693/… is relate to GeoServer CORS Issue. – Ram Aug 15 '18 at 11:55