I’ve been using repl.it all this while but when I tried to import a function from App.jsx
into index.jsx
in vs code it wasnt working .
The code is very simple and I think someone with very basic knowledge can help.
The error in the browser console is →
Uncaught ReferenceError: require is not defined
at <anonymous>:3:12
at run$1 (babel.js:100312:12)
at check (babel.js:100365:11)
at result.<computed>.Object.assign.content (babel.js:100390:11)
at XMLHttpRequest.xhr.onreadystatechange (babel.js:100326:11)
Code in index.jsx
import React from "react"
import Something from "./App";
class App extends React.Component {
render(){
let date = new Date();
const hours = date.getHours();
let timeOfTheDay;
if(hours < 12) timeOfTheDay = "morning";
else if(hours > 12 && hours < 20) timeOfTheDay = "evening"
else timeOfTheDay = "night"
return (
<>
<h1>Good {timeOfTheDay}</h1>
<Something />
</>
)
}
}
const root = document.getElementById("root");
ReactDOM.render(<App />, root);
Code in App.jsx
import React from "react"
export default function Something(){
return(
<h1>Test, why wont this work</h1>
)
}
Extra notes →
Npm version → 6.14.4
Node version → 13.13.0
I didnt use create-react-app
react-dom works. i know this since all the code works if it runs from only a single file.