4

I have the below index.js file:

import ReactDOM from 'react-dom';
import React, { Component } from 'react';

class Aggregator extends Component{
  render(){
    return(
    <div>
    <p>Hello world</p>
  </div>

  );
  }
}

ReactDOM.render(
  <div>
  <Aggregator/>
</div>,
    document.getElementById('content')
);

The HTML file that I am trying to link the above JS file to is index.html. The HTML file is given below:

<!DOCTYPE html>
<html>
<head>

  <title>JS Bin</title>
</head>
<body>
  <div id="content"></div>
  <script src ="./index.js" type="text/javascript"></script>
</body>
</html>

I get a "Target container is not a DOM element" error. I am not sure whether the Javascript file is correctly linked in or what could be the other source of error.

Any help greatly appreciated.

Update: The problem seems to be the same as given in Target container is not a DOM element React.js. But the original question identifies the root cause of the problem but does not mention the solution.

4
  • Are u using webpack?How did u created your react-app? Commented Feb 18, 2018 at 11:43
  • Possible duplicate of Target container is not a DOM element React.js Commented Feb 18, 2018 at 11:44
  • I created my react-app using create-react-app Commented Feb 18, 2018 at 11:59
  • Yes, am using webpack Commented Feb 18, 2018 at 12:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.