Jitsi code in react works in development mode but breaks after running npm build

My Jisti code works fine when testing it with React in development mode but breaks once the code is minified. The error is shown below:

Uncaught (in promise) TypeError: window.JitsiMeetExternalAPI is not a constructor

How do I fix this?
Below is the snippet of how I’m loading the script

  const loadJitsiScript = () => {
    new Promise((resolve) => {
      const script = document.createElement("script");
      script.src = "https://my_domain/external_api.js";
      script.async = true;
      script.onload = resolve;
      document.body.appendChild(script);
    });

    return loadJitsiScript;
  };