What you have is working perfectly in a clean WordPress
installation, using Twenty Seventeen
, so it means the problem is the way in which you are minifying your JS or anything else within this specific WordPress installation.
Do the usual thing, deactivate all plugins and check again, if the problem is gone activate one by one until you find the one causing the problem, I am pretty sure that it’s a plugin, but in case you do that and the problem is still happening, try to use a default template like Twenty Seventeen
.
I have had many similar experiences with plugins like W3 Total Cache
or similar, where I use them and they break things, so I have to find the guilty configuration, which you do the same way as you check for the guilty plugin, you set everything to default and start activating and testing each option to see which one is causing issues.