Do you use inventory size mods?
Factorio only uses one byte (0-255) to index your inventory.
Having a larger inventory will cause this bug when searching your inventory for an item, like an empty blueprint/blueprint book in this case.
There is no way to prevent that, it's just how Factorio was built.