尝试在 AWS EC2 上运行 next.js 时,出现以下错误
Invariant Violation: Unable to find element with ID 109.
at invariant (https://server.com/_next/-/commons.js:127:319)
at precacheChildNodes (https://server.com/_next/-/commons.js:153:42)
at getNodeFromInstance (https://server.com/_next/-/commons.js:162:41)
at ReactDOMComponent.trapBubbledEventsLocal (https://server.com/_next/-/commons.js:10891:14)
at CallbackQueue.notifyAll (https://server.com/_next/-/commons.js:1094:22)
at ReactReconcileTransaction.close (https://server.com/_next/-/commons.js:14780:26)
at ReactReconcileTransaction.closeAll (https://server.com/_next/-/commons.js:357:888)
at ReactReconcileTransaction.perform (https://server.com/_next/-/commons.js:356:621)
at batchedMountComponentIntoNode (https://server.com/_next/-/commons.js:2006:15)
at ReactDefaultBatchingStrategyTransaction.perform (https://server.com/_next/-/commons.js:35
更多信息
- 运行本地服务器时不会发生这种情况
- 总是在直接请求页面而不是通过 AJAX 请求时发生
- 可以通过挂载后渲染一些组件来解决
{
this.state.mounted &&
<Head>
<title>{this.props.title} | Website</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</Head>
}
重现步骤:
只需创建一个页面next/Head
- Cloudflare NGINX 作为反向代理
- Next.js 2.0.0-beta.17
- Node.js v7.3.0