Javascript 未捕获不变冲突:目标容器不是DOM元素。-Reactjs
此代码在本地运行时工作正常。当我在中上传并使用WordPress页面中bundle.js的路径时,就会遇到这个错误。 我在没有注册组件的情况下收到上述错误。任何地方都有一个解决Javascript 未捕获不变冲突:目标容器不是DOM元素。-Reactjs,javascript,reactjs,wordpress,Javascript,Reactjs,Wordpress,此代码在本地运行时工作正常。当我在中上传并使用WordPress页面中bundle.js的路径时,就会遇到这个错误。 我在没有注册组件的情况下收到上述错误。任何地方都有一个解决\u register component错误的方法 我还将document.getElementById(“app”)的值设置为null app.js 从“./node\u modules/React/index”导入React; 从“./node_modules/react dom/index”导入{render};
\u register component
错误的方法
我还将document.getElementById(“app”)
的值设置为null
app.js
从“./node\u modules/React/index”导入React;
从“./node_modules/react dom/index”导入{render};
从“/components/Plans”导入计划;
//导入CSS
导入“/styles/styles.scss”;
常量应用=()=>(
);
var app=document.getElementById(“app”);
console.log(“app”,document.getElementById(“app”))
渲染(,应用程序)代码>
index.html
文件
您的变量“app”未定义。试试这个
render(<App />, document.getElementById('app'));
render(,document.getElementById('app');
在app.js中试试这个
import React from 'react';
import ReactDOM from 'react-dom';
import Plans from "./components/Plans";
//Import CSS
import "./styles/styles.scss";
const App = () => (
<div>
<Plans/>
</div>
);
ReactDOM.hydrate(
<App />,
document.getElementById('app')
);
从“React”导入React;
从“react dom”导入react dom;
从“/components/Plans”导入计划;
//导入CSS
导入“/styles/styles.scss”;
常量应用=()=>(
);
水合物(
,
document.getElementById('app')
);
由于您没有在wordpress中使用index.html
,您需要添加根容器div,以便react用于呈现应用程序。尝试在wordpress html中为应用程序添加div,即
有帮助吗?并非所有这些都与\u registerComponent
这行代码中的app
是什么render(,app)
对不起,我没有粘贴var app=document.getElementById(“app”);谢谢,但是我也试过了,问题仍然存在。
<html>
<head>
</head>
<body>
<div id="app"></div>
<script async src="https://unvisitable-bows.000webhostapp.com/react-widget-subscription-plans/react-widget-subscription-plans/public/bundle.js" crossorigin></script>
</body>
</html>