Uncaught Error: Invariant Violation: _registerComponent(...): Target container is not a DOM element.
初學Reactjs 遇到了這個問題 該如何解決? 花點時間 記錄一下html
頁面:react
<html> <head> <script src="/bundle.js"></script> </head> <body> </body> </html>
js:dom
/** @jsx React.DOM */ 'use strict'; var React = require('react'); var App = React.createClass({ render() { return <h1>Yo</h1>; } }); React.renderComponent(<App />, document.body);
必然會出的錯、
異步
緣由是在頁面加載時js同步下載 而後直接執行 後面的部分尚未加載完畢(body標籤)ui
致使js執行時找不到body標籤節點spa
普及一下:href vs srccode
href 是異步下載component
src 是同步下載htm
因此絕大多數網頁都是 把script標籤放在下面 link標籤放在頭部 ip
來源:http://stackoverflow.com/questions/26566317/invariant-violation-registercomponent-target-container-is-not-a-dom-elem