For future debugging also make sure to run your build command locally when trying to pinpoint what is occuring.
The develop command doesn’t perform the same thing and thus it’s fairly easy to end up in a situation where it appears to “work locally” but “doesn’t work on Netlify”, but it’s really just the difference between what develop is doing and what build does.
In this situation if you run your build command and then serve the output directly with npx serve you’ll find that it displays the same thing as on Netlify.