I don't know if this is a Nextjs bug or a feature. Disabling minification fixes this problem. The fix has to be applied in next.config.json webpack section.:
webpack: (config) => {
config.optimization.minimize = false;
This problem and the fix were also an issue in a React native project that I built, so maybe it's me. But I think it's Nextjs.