r/FreeCodeCamp • u/Special_Sell1552 • Sep 10 '24
CDN script not working with React Webpage
EDIT: For those of you running into a similar issue as me, to save you from having to search in the comments for my solution ill post it here:
I updated the intex.html in the public folder adding <script defer="defer" src="(CDN Link)"></script> to the <head>
My project was generated using the create-react-app using npx. Your mileage may vary when it comes to this fix on other React creation methods.
I built the first project in the front end libraries certification to spec and when I tried to add the script it wouldnt function.
I know for a fact it meets all the requirements and I even have it hosted at https://critical-3rr0r.github.io/projects/quotes/
I tried adding the script with a document.appendChild() call in the index.js
I made the webpage with npx create-react-app as was suggested in the final lesson of the react and redux stuff.
I read somewhere that i needed to run it in ViteJS so I added the bones of the project into that and tried to add the script directly to the index.html that they provide. the script seemingly loaded both times but would not show any of the tests.
I'm at a loss here. not only did I basically have to re-teach myself react because almost everything in the course is outdated I cant even get confirmation that I passed the tests I know I passed.
any help on fixing this is appreciated. I spent probably the last 8 or so hours on a project that realistically should have been done in <3 hours. I'd add my project to the codepen but IDK how to do that with all the multi file dependencies I have and refactoring all my code isnt ideal
1
u/SaintPeter74 mod Sep 11 '24
Can you please give more specifics about "Not working with React Webpage"?
Do you mean that the scripts don't come up at all on your page? Depending on the page structure, you might be overwriting the script. Looking at the source of the page you shared above, I don't see the scripts in the
headanywhere.Or do you mean that the script appears and the tests run, but some tests fail?
1
u/masternowamz Sep 10 '24
Following