Hello, thank you in advance for reading my problem
I got “Uncaught ReferenceError: require is not defined” when I tried to organize my components. I’m currently trying to build a template for a website using React.
This is my script.js:
import HeaderElem from "./component/HeaderElem.js"
const BodyElem = function() {
return (
<div className='BodyElem'>
<h1 className='BodyElem__h1'>I want to join the cool kids</h1>
<ol className='BodyElem__ol'>
<li>I want to join the cool kids</li>
<li>I want to join the cool kids</li>
<li>I want to join the cool kids</li>
<li>I want to join the cool kids</li>
</ol>
</div>
)
}
const FooterElem = function() {
return (
<footer className='FooterElem'>
<small>placeholder text for footer</small>
</footer>
)
}
const Container = function() {
return (
<div className='container'>
<HeaderElem/>
<BodyElem/>
<FooterElem/>
</div>
)
}
const root = document.getElementById('root');
ReactDOM.render(<Container/>, root)
This is my HeaderElem:
const HeaderElemNav = function() {
return (
<ul className='HeaderElemNav__ul'>
<li><a href='#'>Pricing</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Contact</a></li>
</ul>
)
}
const HeaderElem = function() {
return (
<header className='HeaderElem'>
<nav className='HeaderElem__nav'>
<img class='HeaderElem__logo' src='./public/logo.jpg' alt='react logo'></img>
<HeaderElemNav/>
</nav>
</header>
)
}
export default HeaderElem;
This is my HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My awesome page</title>
<link rel="stylesheet" href="styles.css">
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div class="root" id="root">
</div>
<script src="script.js" type="text/babel"></script>
</body>
</html>
here is what my file and folder looks like:
this is in console where it says Uncaught ReferenceError: require is not defined. Im using both Edge and Firefox browser and both says the same error.