Using react-calendly's PopupButton in Next.js throws "Target container is not a DOM element" because the component renders a React portal into rootElement={document.getElementById(...)} during server-side rendering, where document does not exist. The same code worked in plain React but broke under Next.js SSR. Guarding the render with typeof window !== 'undefined' and pointing rootElement at the '__next' div resolved it for the reporter.
react-calendly in Next.js: Target container is not a DOM element
Only render the Calendly component on the client. Either wrap it in a client-side guard that only renders when window is defined (passing the PopupButton its url, rootElement and text props), or load it with next/dynamic with server-side rendering disabled, importing PopupButton from react-calendly. Note the element id must exist in your document (Next.js uses '__next'), otherwise the portal still fails. The reporter confirmed this fixed it.
Source: https://github.com/tcampb/react-calendly/issues/105