The target container is not a DOM element. React.js

I looked through all the other posts that had this problem, but I'm still confused about why I came across this error. I made sure I used id in my

Just started playing with React, so I'm sure this is something pretty stupid.

Thanks for the help in advance.

The code is below.

index.html

<html>
    <head>
    </head>
    <body>
        <div id="testing"></div>
        <script src="index.js"></script>
    </body>
</html>

index.js

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

ReactDOM.render(<App />, document.getElementById('testing'));
registerServiceWorker();

Full error message:

invariant

../app/node_modules/fbjs/lib/invariant.js:42 renderSubtreeIntoContainer
../app/node_modules/react-dom/cjs/react-dom.development.js:15144 render
../app/node_modules/react-dom/cjs/react-dom.development.js:152543 stack frames were expanded.
./src/index.js
../app/src/index.js:6
  3 | import './index.css';
  4 | import App from './App';
  5 | 
> 6 | ReactDOM.render(<App />, document.getElementById('testing'));
  7 | 
  8 | 
  9 | 
View compiled6 stack frames were expanded.
__webpack_require__
../app/webpack/bootstrap 4755e61baeec1360d412:678
fn
../app/webpack/bootstrap 4755e61baeec1360d412:88
0
http://localhost:3000/static/js/bundle.js:35264:18
__webpack_require__
../app/webpack/bootstrap 4755e61baeec1360d412:678
./node_modules/ansi-regex/index.js.module.exports
../app/webpack/bootstrap 4755e61baeec1360d412:724
(anonymous function)
http://localhost:3000/static/js/bundle.js:728:10
+13
source share
3 answers

Be sure to double-check the index.html that you see in your browser. Assuming you are using the create-react-app, so webpack can serve you as another file, either from memory or from a shared folder.

The error was found from the discussion in the comments and chats.

+7
source

React.createElement() :

ReactDOM.render(React.createElement(<App />), document.getElementById('testing'));
+2

html , id ,

ReactDOM.render(, document.getElementById('index'));
0

Source: https://habr.com/ru/post/1689142/


All Articles