I make a website on React.js using a webpack dev server, everything works correctly here. Now I decided to try to just run the index.html file with the linked bundle.js and as a result I get the error in the console: Uncaught Invariant Violation: _registerComponent (...): Target container is not a DOM element.

Html structure:

<body> <div id="container-app"></div> <script src="./build/bundle.js"></script> <script> console.log(document.getElementById('container-app')); </script> </body> 

Rendered like this:

  </Router>, document.getElementById('container-app') 

console.log (document.getElementById ('container-app')); - gives the container I need. What could be the problem?

  • and the second code block you have right in the render? Confused slash at the beginning, which should be at the end </ Router> - user220409
  • This is ReactDOM.render () ending. I just brought him only so that the sheet cannot be laid out all, since the container itself is taken only here. top of course there is <Router> - Alex Slobodyansky
  • "rendered like this" - is it a piece of your code or a piece of bundle? And then you never know what it is there that has been dumped. In general, only the good old step by step debug will help without a minimal working example. - Duck Learns to Take Cover
  • Well, plus are you sure that the problem manifests itself as a result of the rendering of the main route and not as a result of the rendering of the Sabroutes or is there a component of some? - Duck Learns to Take Cover
  • This is a piece of my code. I'm not sure, I just assumed that this container is the only place that is external to the whole filling, and that is where it cannot become attached. How can I try to track down the error? insert debugger or log console in each component? - Alex Slobodyansky

1 answer 1

The problem turned out to be that I tried to import variables from my main js file, which was the entry point for the webpack. After moving the data to another file and importing from there, the project was assembled and started successfully.