Oh, you are right. I forgot to tell you to include this line:
const TY_Scene_Map_OnMapLoaded = Scene_Map.prototype.onMapLoaded;
Above this line, in order to get the mod to be functional.
Scene_Map.prototype.onMapLoaded = function() {
Also, if you don't plan on using the item gain functionality in this mod, specifically these 2 lines:
const id = soulStoneId();
$gameParty.gainItem($dataItems[id], 99);
I would suggest you to remove them, otherwise the affinity mod won't work.