The replaced tile doesn't fit into the players inventory. So it tries to spill it to the ground.
local function insert_or_spill(player, entity, name, count)
local inserted = player.insert{name=name, count=count}
if inserted < count then
entity.surface.spill_item_stack(entity.position, {name = name, count = count - inserted})
end
end
But the problem is probably, that the tile has no position.
A possible fix could be to spill the items at players location instead. Or find another way to determine the position, where it should be spilled