Hello! I’ve been working hard on a React project in CodeCademy and believe I’m including everything needed to make the project work. However, it is not so I’m missing something. Please take a look as I’ve imported the project into a project site.
createRoot(…): Target container is not a DOM element.
It is telling you the element you are getting by id isn’t a DOM element. Why? Because you do not have an element with an app id in the HTML so getElementById is returning null which isn’t a DOM element.
Next error message.
img is a void element tag and must neither have children nor use dangerouslySetInnerHTML.
It is telling you the img element shouldn’t have a closing </img> tag and children and dangerouslySetInnerHTML is in the error message because you have a space inside the element so you have given it content which isn’t valid for an img element. <someElement>some content</someElement>
These are both very confusing to me because I’ve never understood void, and null in any of the languages I’ve studied lol. But I’ll check these and appreciate the help.
I have no idea what you’re saying in the DOM reply lol. I have all of the necessary elements needed AND I’m calling them properly. So idk what you or the counsel log error is saying.
Please show us where your HTML has an element with an id of app. Because as @lasjorg explained above, that’s the element your createRoot call is looking for.
You do not really need to understand null or void to understand the errors.
null is a primitive type, it is basically a “non-existing” object. getElementById is supposed to return an Element object, but if it doesn’t find the element it will return null, as in the object it was asked to return doesn’t exist.
void just means empty. A void element is just an element that can’t have child content because it doesn’t have opening and closing tags.
void is also an operator in JS that can force an expression to return undefined. It isn’t used that often and is unrelated to the void element.
Yes, in that pic of the HTML there is an element with the id of app. But in your HTML there is not. So createRoot(document.getElementById("app")).render(<App />) is going to fail because document.getElementById("app") isn’t going to return an element from the DOM but rather null.
Ohh well I’m not aware of that lol. I thought that is all you were referring too. Edit: That is the only HTML file I have access too there. Also, I don’t get why the instructor has a different HTML file set than I do lol