14

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.... ¡¡¡¡¡

Sushanth --
  • 55,259
  • 9
  • 66
  • 105
Juanma Font
  • 346
  • 5
  • 10
  • I get the same... Meteor was just updated to 1.7 - I ran the tutorial 2 weeks ago when it was still 1.6. Then everything worked. Could they have broken something? https://www.meteor.com/tutorials/react/components – martin Jun 10 '18 at 21:33
  • Won't it be better to use 'meteor create --react'? instead of going through the hassle of creating and then removing the default blaze-template and then add static-html? Nice comment but I believe the best way to go about such error is my removing the default blaze-html-template the follows the creation by simply using your command line(command prompt as the case may) to "meteor remove blaze-html-template" and then "meteor add static-html". I believe this approach will minimize the in the code better. – Mcbriandavids Jan 04 '19 at 01:00
  • thanks for this thread, it was making me crazy. Sadly Scott doesn't update his courses, which is a shame as he is really smart and his content is A-class. – Christian Wolf Alves Hess Oct 01 '19 at 18:17

10 Answers10

48

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
Shraddha Goel
  • 869
  • 7
  • 18
29

If you removed blaze-html-templates you need to add static-html package to compile your index.html and avoid this error (see Meteor Guide, end of paragraph):

 meteor add static-html
Xavier Priour
  • 2,121
  • 1
  • 12
  • 16
14

I had the same problem. This is how I solved it.

In your terminal type the following lines in the project directory.

meteor remove blaze-html-templates
meteor add static-html
Salamit
  • 1,015
  • 7
  • 13
8

For me I just needed to import the .html file before I tried to render to the DOM.

import './main.html';

JoshJoe
  • 1,482
  • 2
  • 17
  • 35
5
meteor remove blaze-html-templates
meteor add static-html
Ahmad Samawi
  • 51
  • 1
  • 1
1

Add your script tag to before the closing </body> tag most likely the script loaded before your DOM ID.

also switch this around...

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

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

Meteor.startup(() => {
  render(<App />, document.getElementById('render-target'));
});
Chris Hawkes
  • 11,923
  • 6
  • 58
  • 68
1

First remove blaze template dependency

meteor remove blaze-html-templates

Then add static html

meteor add static-html
Nimmi Verma
  • 465
  • 6
  • 11
  • please use formatting for better readability :) https://stackoverflow.com/help/formatting – chip Sep 15 '18 at 16:38
0

I had removed the package (blaze-html-templates) .

I assumed that being a Meteor+React would not be necessary but it is used to compile the main.html.

Adding the package blaze-html-templates with

meteor add blaze-html-templates

solve the problem.

Juanma Font
  • 346
  • 5
  • 10
0

In my case the fix was simple. In HTML change class to id.

render( <h1>Hello</h1>, document.getElementById("app"))

<body>
<div class="app"><`enter code here`/div>
</body>

<body>
<div id="app"><`enter code here`/div>
</body>
ispirett
  • 648
  • 10
  • 10
0

This is an old post but it's #1 in google results so...

I was getting this error on my android build but not web, already removed blaze and added statichtml..

My issue ended up being that I had a favicon and manifest.json being imported in my html but I hadn't gotten around to creating them yet.

I removed the links and it worked like a charm.

Hopefully this can save someone a few hours of digging.

Sébastien Temprado
  • 1,413
  • 4
  • 18
  • 29
Karina Y
  • 1
  • 1
  • 3