Hi,
This could be hardware or the BIOS.
In the case of hardware, it could be dirt, a bad fit, or a faulty M.2 port itself, or a faulty cable if using SATA.
It's also possible that the SSD or HDD itself is faulty.
If it's a laptop or desktop, if possible, could you provide the laptop model or your desktop configuration?
Thanks