0

I'm doing a react project for school and am getting the following error when trying to load the web server:

Error: Target container is not a DOM element. react-dom.development.js:26091
    render React
    js index.js:7
    js main.chunk.js:566
    Webpack 7
        __webpack_require__
        fn
        1
        __webpack_require__
        checkDeferredModules
        webpackJsonpCallback
        <anonymous>

The index.js code looks like this:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: 
reportWebVitals();

How can I solve this so I can start playing around with the look of the webpage?

JS1
  • 1
  • 1
  • Does this answer your question? [React Error: Target Container is not a DOM Element](https://stackoverflow.com/questions/26416334/react-error-target-container-is-not-a-dom-element) – Håken Lid Mar 03 '21 at 22:30

1 Answers1

0

I would check your public/index.html file and make sure you've got this in there.

<div id="root"></div>

Did you use

npx create-react-app my-app

to get started? It will generate this file with the root div for you automatically