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

查看:105
本文介绍了流星反应错误:修复后目标容器不是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:

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:

未捕获的错误:_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 在也许Ready(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.

方法1 只需在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

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

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