It seems to be happening only with automated build using godot command line (headless or not).
When launching the game from the command line we can see the following error: ERROR: Failed to load script "res://scenes/ui/scripts/leaderboard.gd" with error "Parse error". which cannot be seen when running from Godot editor or exporting using the editor.
Ok this is stupid.. I was exporting with an older version of Godot (4.1.3) which doesn't support typed for loops.. The export was working but the script was not parsed correctly at launch.
It seems to be happening only with automated build using godot command line (headless or not).
When launching the game from the command line we can see the following error: ERROR: Failed to load script
"res://scenes/ui/scripts/leaderboard.gd" with error "Parse error
". which cannot be seen when running from Godot editor or exporting using the editor.