The exception is the function named "main". That one cannot appear inside another function. If you try to do that, you get the error message you list.
Can this also happen if you are importing scripts that have their own mains?
When I mentioned this a couple years ago, I was publicly informed that I was wrong, and privately informed that I was clearly an inferior programmer because I did that, so, your milage may vary.![]()