Meteor-React 错误:修复后目标容器不是 DOM 元素 [英] Meteor-React Error: Target Container is not a DOM element, after fix

查看:15
本文介绍了Meteor-React 错误:修复后目标容器不是 DOM 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从以下位置复制并粘贴代码:https://stackoverflow.com/questions/41514549/

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

然后,我修复错误并通过id"更改class",因此:

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

ma​​in.html

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

ma​​in.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:

未捕获的错误:_registerComponent(...):目标容器不是 DOM元素.在不变(modules.js?hash=de726ed…:12672)在 Object._renderNewRootComponent (modules.js?hash=de726ed…:30752)在 Object._renderSubtreeIntoContainer (modules.js?hash=de726ed…:30842)在渲染(modules.js?hash=de726ed…:30863)在 app.js?hash=71ef103…:46在maybeReady (meteor.js?hash=27829e9…:809)在 HTMLDocument.loadingCompleted (meteor.js?hash=27829e9…:821)

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

推荐答案

基本上是 HTML 渲染导致的问题.当您创建流星应用程序时,默认情况下它会出现火焰&您正在处理带有反应的流星或带有角度的流星.您可以通过两种方法解决此错误.

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.

方法一只需在 main.js 中添加 import 语句

Method 1 just add import statement in main.js

import './main.html';

方法 2 首选,因为这是我的选择

Method 2 Preferrable as it is my choice

meteor remove blaze-html-templates
meteor add static-html

这篇关于Meteor-React 错误:修复后目标容器不是 DOM 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆