How do I get esbuild to stop renaming things?

In upgrading my SpreeCommerce app, I’ve been trying to use esbuild as the JS bundler. I’m treating the Spree frontend JS files as a vendor directory in the app, trying to get esbuild to bundle the files I need. At this point esbuild bundles the files, but winds up renaming the namespace/function Spree to Spree2 when encountering it. This results in the error Uncaught ReferenceError: Spree is not defined.

Spree is defined here: https://github.com/spree/spree_rails_frontend/blob/4-5-stable/app/assets/javascripts/spree/frontend/main.js. Confirmed using esbuild 0.24.0. Thoughts and attempts based on what I’ve read on the topic:

  • Are some of the methods defined there conflicting with esbuild?
  • Is esbuild somehow reading the namespace from the Rails side of the
    application and thinking there’s a conflict?
  • Tried changing the function Spree line to export function Spree () {}
  • Tried export { Spree } from './vendor/spree/frontend/main.js' in application.js
  • Tried setting keepNames: true, in esbuild config options
  • Tried changing the load order and plenty other things which only resulted in more errors

build/application.js:

  // app/assets/javascripts/vendor/spree/frontend/main.js
  var import_jsuri2 = __toESM(require_Uri());
  var import_jsuri3 = __toESM(require_Uri());
  function Spree2() {
  }
  console.log("main.js");
  Spree2.ready = function(callback) {

Import Uri from 'Jsuri' has also not been working properly, but that’s a simpler issue to fix. Would appreciate other suggestions to try, other than renaming Spree to Spree2 in the rest of the JS (yikes!)