Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor-React Error: Target Container is not a DOM element, after fix

I copy+paste the code from : https://stackoverflow.com/questions/41514549/

Then, I fix error and change 'class' by 'id' so:

main.html

<head>
  <title>React Meteor Voting</title>
</head>
<body>
  <div id="render-target"></div>
</body>

main.jsx

import React, { Component } from 'react';
import {Meteor} from 'meteor/meteor';
import { render } from 'react-dom';

Meteor.startup(() => {
  render(<App />, document.getElementById('render-target'));
});

class App extends Component {
  render(){
    return (
      <h1>Hello!</h1>
    );
  }
}

package.json

{
  "name": "test-react",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "babel-runtime": "^6.20.0",
    "meteor-node-stubs": "~0.2.4",
    "react": "^15.5.4",
    "react-dom": "^15.5.4"
  }
}

But I got the same error:

Uncaught Error: _registerComponent(...): Target container is not a DOM element. at invariant (modules.js?hash=de726ed…:12672) at Object._renderNewRootComponent (modules.js?hash=de726ed…:30752) at Object._renderSubtreeIntoContainer (modules.js?hash=de726ed…:30842) at render (modules.js?hash=de726ed…:30863) at app.js?hash=71ef103…:46 at maybeReady (meteor.js?hash=27829e9…:809) at HTMLDocument.loadingCompleted (meteor.js?hash=27829e9…:821)

Is driving me crazy.... ¡¡¡¡¡

like image 568
Juanma Font Avatar asked Jun 12 '17 19:06

Juanma Font


1 Answers

Basically, the problem occurs due to HTML rendering. When you create meteor app it comes up with the blaze by default & you are working on the meteor with react or meteor with angular. You solve this error by two methods.

Method 1 just add import statement in main.js

import './main.html';

Method 2 Preferrable as it is my choice

meteor remove blaze-html-templates
meteor add static-html
like image 88
Shraddha Goel Avatar answered Oct 05 '22 22:10

Shraddha Goel