Fix CORS Error [SOLVED] | React Tutorial

Поділитися
Вставка
  • Опубліковано 21 сер 2024
  • This video tutorial, I will demonstrate to you how to solve the CORS issue in ReactJS.
    GitHub Pages URL
    lyhd.github.io...
    GitHub Repo
    github.com/lyh...
    Temporary solutions:
    Run Chrome without CORS
    alfilatov.com/...
    Browser Plugin
    chrome.google....
    cors-anywhere.h... + [API URL]
    Free APIs:
    github.com/pub...
    People experience the issue
    github.com/axi...
    Click to Subscribe: bit.ly/Subscrib... & turn on notifications to find out when I upload new videos.
    Website: honglytech.com
    Medium: / lyhong.rupp
    #reactjs #cors #reacttutorial
  • Наука та технологія

КОМЕНТАРІ • 275

  • @honglytech
    @honglytech  5 років тому +250

    Skip to solution: 20:08

  • @benfranklin4494
    @benfranklin4494 4 роки тому +49

    first 20min he was just wasting time. sir we already know we have the problem, still u spend 20mins browsing the problem, we came here just to see the solution not to memorize the cors problem.

  • @Drew7795
    @Drew7795 2 роки тому +3

    Two days trying to fix my problem. And with just one line of code, just a proxy in the package and boom...everything resolved. Thanks, man! Thank you very much.

  • @kern6365
    @kern6365 4 роки тому +7

    This solution is just for fetching static data, what about the one with query needed? also the package.json solution does not work at all, why would you put the api as your proxy?

  • @wuwei7135
    @wuwei7135 4 роки тому +7

    thank you very much! I found so many approaches and I still was confused for hours and you went through all of it, I just am glad now..time for a break x'D

  • @marcelosdm86
    @marcelosdm86 4 роки тому +5

    Hey, I'm just passing by to thank you VERY MUCH! You really taught me alot about CORS in this video, and helped me fix a problem!

  • @joao9085
    @joao9085 2 роки тому

    i hate that u spend 30 min to write a simple line in package.json, but i luv that u solve my issue lol

  • @13has
    @13has 4 роки тому +7

    This solved it for when running locally, but when deployed with AWS Amplify the call returns an HTML file, not the JSON data I'm getting back when running it locally.

    • @anandissac3582
      @anandissac3582 4 роки тому

      I have the exact same problem. Did you find a solution ?

    • @vaibhavshinde6926
      @vaibhavshinde6926 2 роки тому

      I also have same issue. You found any solution

    • @ruchipatel3375
      @ruchipatel3375 Рік тому

      same. have you found solution?

  • @erickgutierrez5260
    @erickgutierrez5260 4 роки тому +7

    Thank you, after spending hours, finally I found your video!!

    • @pinch5378
      @pinch5378 3 роки тому

      And you spent 26 min here

  • @kaushikayinala9712
    @kaushikayinala9712 3 роки тому +5

    Don't use this solution, you can not deploy your react-app in webserver. You need nodejs to run your app. The CORS problem can only be resolved in the server-side code. The solution suggested in this video is forwarding the HTTP request to a nodejs server and nodejs server will make the HTTP request and forwards the response to the web client.

    • @ashwinpatil6103
      @ashwinpatil6103 2 роки тому

      If you can provide a solution to this it would be great.
      Springboot server with reactJS client , help if possible !

    • @yangkai934
      @yangkai934 Рік тому

      @@ashwinpatil6103 did you find solution?

  • @user-fk9pc2yu4t
    @user-fk9pc2yu4t 3 роки тому +3

    Thank you. I've been watching it since 20:11

  • @ayushikeshri4281
    @ayushikeshri4281 4 роки тому +7

    the best solution ever found, you explain so well sir. I was stucked and you gave the whole new level of explaination. Thankyou so much

    • @honglytech
      @honglytech  4 роки тому

      Thanks for your kind words!

  • @beenicula
    @beenicula 3 роки тому +12

    You're a life saver. You explained everything perfectly and provided such clear, concise solutions. Saved me so much time.

    • @honglytech
      @honglytech  3 роки тому +2

      Thank you. I was struggling the same as you and I know this will help people out there including you. I’m glad this video helped

  • @marialali1734
    @marialali1734 3 роки тому +1

    Thank you so much! Literally spent 4 hours before I found your video!

    • @honglytech
      @honglytech  3 роки тому

      I feel your pain! Glad this video helped you solved the issue.

  • @kninfotechin
    @kninfotechin 4 роки тому +1

    After wasting whole day.. got fixed by your trick. thanks man.

  • @arjun-de6dr
    @arjun-de6dr 3 роки тому +2

    Thanks a ton, spent so much time figuring this out , your video is so much detailed.

  • @seongeunlee609
    @seongeunlee609 2 роки тому

    I have been searching for this solution for 4 days.. really really thank you from South Korea... I've just subcribed to you

  • @monikasahai6492
    @monikasahai6492 4 роки тому +2

    THANK YOU so much! I had been trying to find a solution to this problem since an hour. I was lost because I am new to React. I could access it from browser but not from my React app. This worked for me! \m/

    • @honglytech
      @honglytech  4 роки тому +1

      Monika Sahai Happy to hear that!

  • @beenicula
    @beenicula 3 роки тому +3

    This is such a useful video. You're an excellent teacher.

  • @samgak_imbap862
    @samgak_imbap862 2 роки тому

    You really saved my life. Providing such an easy and straightfoward answer! thank you!

  • @kaylamartinez3459
    @kaylamartinez3459 3 роки тому

    I see people commenting a lot of hate, but THANK YOU for your video! It was the answer to my bug!

  • @widiaretasafitri9935
    @widiaretasafitri9935 3 роки тому

    Thank you very much!!!! I've searching the solution for many hours, but nothing can solve, Really appreciate this solution!!

  • @JuanJose-ls9mm
    @JuanJose-ls9mm 3 роки тому +2

    This doesn't work on production mode. Has anyone managed to solve that?

  • @haikazahid4665
    @haikazahid4665 4 роки тому +2

    You are a true LIFE SAVER, thanks alot

  • @temiemmanuel3580
    @temiemmanuel3580 3 роки тому

    It was worth the long video. Thanks a lot.

  • @fmaciel2
    @fmaciel2 3 роки тому +2

    Thank you *VERY MUCH*! You saved me after hours and hours of researching!

    • @honglytech
      @honglytech  3 роки тому +1

      I’m so glad you found it helpful. I was struggling the same.

  • @sakurademon9823
    @sakurademon9823 3 роки тому +1

    Hi, I have tried your solution. It works on localserver but not when I host the project to GitHub Pages. Please help

  • @DanHajek85
    @DanHajek85 4 роки тому +1

    This video help me to solve the CORS issue. Many thanks buddy!

  • @raidenc9846
    @raidenc9846 2 роки тому

    watching this in 2021, still fixing my goddam issues perfectly!! Thank you so much!

  • @KingTMK
    @KingTMK 2 роки тому +1

    Great solution. Bless you for saving everyone's time!

  • @viniciusmantovani8619
    @viniciusmantovani8619 2 роки тому

    You are the best. I needed this for a project and you really saved me! Thank you so much!!!

  • @khamlasiyivang2145
    @khamlasiyivang2145 3 роки тому

    Thank you, man. You have safe my life. Once again appreciated what you are doing

  • @alperenarici5851
    @alperenarici5851 4 роки тому +2

    Thank you I try for 2 days. I asked a question to stackoverflow butI could not get an answer. Thank for video again.

    • @honglytech
      @honglytech  4 роки тому

      I'm glad that I could help you.

  • @marcelafreire6235
    @marcelafreire6235 4 роки тому

    I I spent all day long searching trying to fix this, you saved me! haha thankssss

    • @honglytech
      @honglytech  4 роки тому

      Marcela Freire Happy that this tutorial helps!

  • @danishbukhari6693
    @danishbukhari6693 2 роки тому

    this video was really helpful after wasting my 12 hours I got this solution , thank you so much for the video :)

  • @meshu_amare
    @meshu_amare Рік тому

    Thank you so much! this problem spends, up all my day! you save my night !

  • @dogukaneren7163
    @dogukaneren7163 2 роки тому +1

    Thank you man 20:10 is very helpful

  • @cutiegorgeous1
    @cutiegorgeous1 3 роки тому

    Finally.. I have solved this error after watching this video :) Thanks a lot.

  • @mle3638
    @mle3638 4 роки тому +1

    Thanks for the video.
    I followed all the steps and it's working when it's just one but when I implement the more than one URL step I'm getting an error when starting the project that says 'proxy is not function'.
    Any hint here?
    Thanks

    • @de_leon
      @de_leon 4 роки тому

      you need use createProxyMiddleware for new version

  • @elmcapp6032
    @elmcapp6032 2 роки тому

    Thank you. one recommendation add chapters to long videos so that we can just jump to the solution without all the other info

  • @mikki7522
    @mikki7522 4 роки тому

    Wow it worked! Finally! Thank you man.

  • @alexbarasa3816
    @alexbarasa3816 2 роки тому

    Life saver. thanks so much. after 2 days. finally.

  • @dramastar30
    @dramastar30 3 роки тому

    You are ❤️. Hats off 🎩. Bless you man for creating this video. Saved a great deal of time for me. 👍🏻👍🏻👍🏻

  • @tfist
    @tfist 2 роки тому

    kudos, great solution!

  • @husnulmub9956
    @husnulmub9956 4 роки тому +2

    i have try it and working fines, thanks :D

  • @DanielRodrigues-bx6lr
    @DanielRodrigues-bx6lr 2 роки тому

    It tells me proxy is not a function. When I change the first line to an import statement instead of a require, it says import cannot be used outside of a module.

  • @MiroCro11
    @MiroCro11 4 роки тому

    This solution worked for me! Thank you very much!

  • @danielxxgadd
    @danielxxgadd 4 роки тому

    What I dont understand is I am not using a proxy, I am simply cunsuming another API , why then do i need label my other API as a proxy, its not bouncing from thatr to something else , instead it just getting from that ?

  • @MG-bm5oj
    @MG-bm5oj 4 роки тому +1

    Thanks. very helpful the whole video.

  • @mnjalawalter6336
    @mnjalawalter6336 3 роки тому

    What a video😁such errors can make you rethink your careeer

  • @k1ngydoteth403
    @k1ngydoteth403 4 роки тому +2

    You are the man!

  • @statuschannel8572
    @statuschannel8572 2 роки тому

    you save my life, thanks

  • @steven_charles
    @steven_charles 2 роки тому

    Perfect solution! Thanks a ton!

  • @ibrahimalici2132
    @ibrahimalici2132 4 роки тому

    Hi, How can i connect with React Native Mobile app to Asp.Net Signalr. This error => has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

  • @sarahcarter315
    @sarahcarter315 3 роки тому

    Hello! This works perfect when I run my app locally, but my res.data response is undefined when I deploy it to Heroku. How can I fix this?

  • @grzegorzmolin
    @grzegorzmolin 2 роки тому

    LIFESAVER!!! Thanks man!

  • @TheBobGlaser
    @TheBobGlaser 4 роки тому

    Thank you so much. It worked the first time.

  • @Mohamed-M-M
    @Mohamed-M-M 3 роки тому +1

    Thank you, Life Saver...

  • @datng2312
    @datng2312 2 роки тому

    Appreciate it man!

  • @ReBoRNxFuze
    @ReBoRNxFuze 2 роки тому

    Thank you ! I was just wondering why we have to add the proxy , why doesn’t react just let us call the api regularly ?

  • @siberjanaxhabafti325
    @siberjanaxhabafti325 3 роки тому

    Hello, thanks for the video. I'm creating an Ionic React app, running on top of Capacitor. Your solution solved my CORS issue when I run my app in the browser (ionic serve), but when I try to run my app on an Android emulator, the proxy in package.json is totally ignored by Android. Do you have any idea how to solve this?

  • @damonwu9658
    @damonwu9658 3 роки тому

    Thanks Hong Ly, I got a question, how to handle create-next-app proxy settings? Coz this solution doesn't work for create-next-app so far

  • @grach1993
    @grach1993 3 роки тому

    Thank you, man! You brought me to life.

  • @morsecode9689
    @morsecode9689 2 роки тому

    lon live man. love u....u really helped me explained perfectly

  • @naiemfoysal6974
    @naiemfoysal6974 3 роки тому

    I using npm i cors. It works. But when I upload image/file in my website. It still shows the cors error. How can I fixed that for upload files/images in server.

  • @caiolucena498
    @caiolucena498 4 роки тому +1

    thanks dude, helped me a lot

  • @pareshanbabai
    @pareshanbabai Рік тому

    Thanks Man You are Legend

  • @soymartinacosta
    @soymartinacosta 4 роки тому

    Thanks! Solved in IonicFramework creating the SetupProxy.js in the src folder and importing js file :)

  • @ivo9339
    @ivo9339 3 роки тому +1

    Thank you Hong Ly

  • @sleepmusicforme
    @sleepmusicforme 2 роки тому

    Hello its not working after build can you help me with that?

  • @dulcineapena7613
    @dulcineapena7613 4 роки тому

    This is a very useful video! Thanks a lot, I've been dealing with this problem since the morning and finally my api request works with a custom query and headers. Only one question, we are using the same api between multiple persons, but only in my computer I have this problem... why could it be that?

    • @honglytech
      @honglytech  4 роки тому

      Thanks Dulcinea. The issue that only happens on your computer could be that you and your teammates are running on different browsers, versions and more.

  • @compean7360
    @compean7360 2 роки тому

    Awesome! works!

  • @abc_cba
    @abc_cba 3 роки тому

    Hi, i get this error "react-scripts@4.0.1 has 1 high, 82 medium vulns" in package.json , i tried updating the package synk_vulns but nothing worked. Can you kindly help me,please ?

    • @honglytech
      @honglytech  3 роки тому

      You can try this
      stackoverflow.com/questions/49582891/proper-way-to-fix-potential-security-vulnerability-in-a-dependency-defined-in-pa

  • @ammarali3589
    @ammarali3589 Рік тому +1

    Nothing works!

  • @rizwanullah2589
    @rizwanullah2589 2 роки тому

    Thank you, Dear. This solves my issue.

  • @chrispolyman5097
    @chrispolyman5097 2 роки тому

    Fantastic! thank you Ly

  • @yuvrajagarkar8942
    @yuvrajagarkar8942 3 роки тому

    but the proxy solution won't work in production right ?

  • @rinchen_
    @rinchen_ 3 роки тому

    Proxy solution works great - but i'm just wondering if there's any drawbacks to this?

  • @ashwinpatil6103
    @ashwinpatil6103 2 роки тому

    I love you bro
    NO HOMO

  • @vickyraj7045
    @vickyraj7045 3 роки тому

    able to solve the problem but not able to call another uri with same url but requestMapping different

  • @amirsalehi3643
    @amirsalehi3643 Рік тому

    Thank you so mush . It solved my error.

  • @bwustinbweem
    @bwustinbweem 2 роки тому

    legend.. legend

  • @urbanavicius
    @urbanavicius 2 роки тому

    Thank you very much! It really helped!

  • @stephenwhelan606
    @stephenwhelan606 2 роки тому

    Thank you so much! So helpful!

  • @markonikolic6346
    @markonikolic6346 3 роки тому

    The solution is at 20:34. Don't waste your time watching the whole thing

  • @AryanSinghBCS
    @AryanSinghBCS 3 роки тому

    for people running django as backend you guys can use corsheaders

  • @Tiruvengadam85
    @Tiruvengadam85 4 роки тому

    if the end point is same and URL is different, how to handle in that case

  • @marouanesd2480
    @marouanesd2480 2 роки тому

    It works very well, thank you.

  • @bryanferry6409
    @bryanferry6409 3 роки тому

    how fix this error > Missing required request header. Must specify one of: origin,x-requested-with

  • @lizaveta_mak
    @lizaveta_mak 4 роки тому

    Thank you very much! Your video is very useful.

  • @sabujjana2860
    @sabujjana2860 4 роки тому

    how to deploy it to netlify ? this is not working in production.

  • @viniciusbuzato
    @viniciusbuzato 3 роки тому

    Thank's man! It worked!!

  • @AWT_GOLD_TRADING
    @AWT_GOLD_TRADING 4 роки тому

    THANKS MAN U SAVED MY LIFE

    • @honglytech
      @honglytech  4 роки тому

      jacob radan I’m glad it helps

  • @anthonycalo4047
    @anthonycalo4047 3 роки тому

    Thank you! Finally a solution.
    Almost smashed my PC lol

    • @honglytech
      @honglytech  3 роки тому

      I’m glad you didn’t 😆

  • @ZeeshanAli-nm7eq
    @ZeeshanAli-nm7eq 4 роки тому

    THANK YOU SO MUCH!
    This was getting me mad, finally it worked, THANK GOD, and THANKS TO YOU! =)

    • @honglytech
      @honglytech  4 роки тому +1

      I’m glad that this video helped to solve your issue :)

  • @victorpotes
    @victorpotes 3 роки тому

    Hey! Thank you so much, you saved me. However, I'm having a problem with one of the calls I make to my API, I have to call to one API rest twice but with different methods (GET and POST) when I make the first call it works, but the second one not and as I could see, the proxy doesn't change the target to make the call, having as issue 403 forbidden. Can someone help me please? Thanks

  • @3hsemail
    @3hsemail 3 роки тому

    Hi @Hong Ly,
    I hope you are doing well.
    I hope you can help me with this:
    1. I installed the http-proxy-middleware package as you said
    2. Created the setupProxy.js under src
    3. Added the code as in the video
    4. Restarted my application but I am getting this issue:
    proxy is not a function
    Thanks in advance.

    • @honglytech
      @honglytech  3 роки тому

      You can take a look at the source code. Link is in the video description.

  • @musadulislam3128
    @musadulislam3128 3 роки тому

    Nice work. Thank you.

  • @unknownlion5441
    @unknownlion5441 3 роки тому

    Can u please tell me how to resolve provisional header are shown problem

  • @hasanugr
    @hasanugr 2 роки тому

    Thank you so much, you saved my time. :)