next.js: Invariant Violation: Unable to find element with ID XX

When trying to run next.js on an AWS EC2, the following error was observed

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

More Info

  • This does not occur when running a local server
  • Always happens when a page is requested directly and never through AJAX
  • Can be solved by rendering some components after mount

Eg. next/Head

      {
        this.state.mounted &&
        <Head>
          <title>{this.props.title} | Website</title>
          <meta name="viewport" content="initial-scale=1.0, width=device-width" />
        </Head>
      }

Steps to reproduce:

Just create a page with next/Head

Other

  • Cloudflare NGINX as reverse proxy
  • Next.js 2.0.0-beta.17
  • Node.js v7.3.0

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 3
  • Comments: 22 (5 by maintainers)

Commits related to this issue

Most upvoted comments

In my case <noscript> was causing this error. To avoid this I had to use dangerouslySetInnerHTML:

...
const staticMarkup = ReactDOMServer.renderToStaticMarkup(markup)

return <noscript dangerouslySetInnerHTML={{ __html: staticMarkup }} />

(Above solution found in https://github.com/zeit/next.js/pull/2767/files)

I caused this error when server rendering by having li as a descandant of another li. If you have this warning in development, this error will occur when attempting server rendering.

@arunoda How is this a question and not a bug? Just creating a page with a next/Head causes the error to pop up.

in my case , i used html p (p in p) tag nested and in webpack dev server works without error , when i build the project and run the code in express and ssr (server side rendering) this error logged. even though disable ssr in this component , problem not solved . just change parent tag to <section> solved the problem.

Mine was due to invalid HTML—fixed by adding a <tbody> inside my <table>

This looks like a hidden bug in React itself: https://github.com/facebook/react/issues/7093