I had a similar problem with an nvme and it turned out it wasn't seated properly in its slot. It was sitting very slightly at an angle even with the screw in place. I had the same problem with it sometimes being detected at boot and sometimes not.
I'd double check it's fully and correctly inserted into it's slot before writing it off as defective.