I’m having trouble integrating a Calendly widget into my Next.js 13.5 application. I’ve attempted two different methods but keep running into errors. Any help would be appreciated.
Problem 1: Direct Script Implementation
First, I tried using Calendly’s native script approach with this code:
"use client";
import Head from "next/head";
import React, { useEffect } from "react";
export default function BookingWidget() {
useEffect(() => {
window.CalendlyWidget.setupInlineEmbed({
url: "my-calendly-url",
parentElement: document.querySelector("#booking-container"),
});
});
return (
<>
<Head>
<script
src="https://assets.calendly.com/assets/external/widget.js"
type="text/javascript"
async
></script>
</Head>
<div
id="booking-container"
style={{ minWidth: 300, height: 600 }}
data-auto-load="false"
></div>
</>
);
}
This throws an error:
TypeError: Cannot read properties of undefined (reading 'setupInlineEmbed')
Problem 2: Using react-calendly Package
Then I switched to the react-calendly npm package, but got this error instead:
Error: Object prototype may only be an Object or null: undefined
I’ve been struggling with this for days. Has anyone successfully implemented Calendly in Next.js 13.5? What am I missing here? Thanks for any suggestions!