I finished the Random Quote Machine challenge which I made in Visual Studio Code with the live server extension and after it I uploaded the code to a codepen in order to fulfill the challenge. In both, live server and codepen, works and looks as expected but when I open the index.html from my folder (see both images below) the webpage is displayed without the react component:
I see. I’ve tried rendering a simple component like that one and evidently the issue lies in something codepen/live server has inherently that our scripts lack.
I’ve copied and pasted URL from other people’s codepen. The URL for react seems to be different from the one you find when searching for it in the pen setting
This is all a mystery to me as well. The FreeCodeCamp course on React doesn’t teach us how to set up React. I mean what’s the point of learning the rest of the stuff if I’m stuck on step one?
to try and figure how how this person got react to work. For me, I boiled it down to the URL link because the 16.8.8 link doesn’t work in this guy’s codepen either. For you, I’m not sure. Have you tried the URL link I suggested on a simple component?
Yes, but it didn’t work either. I’ve figured out that the error has something to do with this because when opening html files in the browser I’m getting the “Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/Users/Lucas/Desktop/show/script.js. (Reason: CORS request not http)” error.
So your browser is enforcing CORS (Cross Origin Resource Sharing) and preventing you from loading your .js file.
CORS is basically a system that says any requests for files and/or data from another origin requires permission from that origin before allowing you to use it. These permissions are usually passed in the HTTP request headers.
Your browser is telling you that one of the policies in CORS is that it won’t load resources that come from file:/// urls which is why it isn’t working from the folder view. This is a common problem faced with single page applications.
Hopefully someone else can come along and suggest a course that will teach you the in’s and out’s of working with express but this should get you started.