React Course: Uncaught ReferenceError: require is not defined


Beginner javascript and react learner here. I am taking the React Course - Beginner’s Tutorial for React JavaScript Library [2022] on Youtube.

I am working on my local environment and using the CDN links.

I am stuck at exporting and importing the Header, Footer, and Main Content. The section starts at 1:26:21 and ends at 1:31:58.

My code looks exactly like the video. I’ve created separate files for the Header, Main Content, and Footer. I exported the Header, Footer, and Main Content. And I imported each into my index.js file. But when I preview the page is blank. The console gives this error:

Uncaught ReferenceError: require is not defined

Do I need to install React on my machine using Node for the code to work?

I can’t seem to post all of my code on here, but it is exactly like the video though I’m still using the CDN links and I’m not on Scrimba.

Thank you for any help and advice.

Can you create a repo so we can see what is happening?

As far as I know, component import/export is not going to work with just the CDN link (without a build process). You will have to have all the components in index.js (or the HTML with a script element).

I would highly recommend you use Vite and not CDN links. Or an online editor like StackBlitz or CodeSandbox.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.