ESP32 Runs only when compiled on M1 MAC

You have not specified the version of the platform.
It is therefore possible that different platform versions could be used on different computers / vm’s.

Which platform version are you using on your M1 Mac (on which it runs flawlessly)?

Then specify the this version in the platformio.ini e.g.:
platform = espressif32 @ 6.5.0.

Please show the warnings.

Please use the pre-formatted text for code, logs and configuration files.