Unfortunately the only fix I found was adding this to my next.config.mjs
webpack: (config) => {
config.optimization.minimize = false;
return config;
},
And the code runs properly with no build errors, or console errors or warnings. I don't know what causes this settings being turned on, to not function.