Solved it by excluding @azure/service-bus from the bundler. Next.js has a feature for that: https://nextjs.org/docs/app/api-reference/config/next-config-js/serverExternalPackages
// in next.config.js
/** @type {import("next").NextConfig} */
const config = {
serverExternalPackages: ["@azure/service-bus"],
};