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