Search code examples
reactjscorscreate-react-app

CORS issue using create-react-app when trying to use an image from another URL


I normally create my react projects with a static express server but figured I would give create-react-app a shot.

However I am running into an issue with my current project. When trying to use an img tag in the react code and use the src URL from another site I get a CORS issue.

"Access to image at 'http://www.dailygarnish.com/wp-content/uploads/2012/04/IMG_20120414_205845-640x640.jpg' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

This works perfectly fine normally on Apps where I created the server, but not with create-react-app

Any advice would be appreciated


Solution

  • Try putting this in your package.json, and then restart CRA dev server(must be done):

    "proxy": "https://cors-anywhere.herokuapp.com/"