__name function being injected, js is being mangled, website is broken

For Workers & Pages, what is the name of the domain?

What is the error number?

ReferenceError: Can’t find variable: __name

What is the error message?

ReferenceError: Can’t find variable: __name

What is the issue or error you’re encountering

Something is mangling the JS on my website - what is injecting this __name() call?

What steps have you taken to resolve the issue?

Something in wrangler or the worker is mangling the javascript…

I encountered a similar issue while using next-themes. Based on my testing, I found a way to reproduce it:

import React from "react";

const code = function () {
  const issueFunction = function () {
    console.log("issue");
  };

  const event = window.matchMedia("(prefers-color-scheme: dark)");

  event.addEventListener("change", function () {
    // This is the part that causes the issue
    issueFunction();
  });
};

const getIssue = `(${code})();`;

export function IssueDemo() {
  return <script dangerouslySetInnerHTML={{ __html: getIssue }} />;
}

// The transformed code is as follows

<script>
(function() {
    let e3 = /* @__PURE__ */
    __name(function() { // When I turn off minify, the error is Can't find variable: __name; when on, it's Can't find variable: e
        console.log("issue");
    }, "e3");
    window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() {
        e3();
    });
})();
</script>

I am using opennext, and I’m not sure what is affecting it. The project dependencies are as follows:

  • @opennextjs/cloudflare”: “^1.0.0-beta.2” // The same issue occurs with 0.6.6
  • “wrangler”: “^4.10.0”
  • “next”: “15.3.0”
  • “next-themes”: “^0.4.6”