Either the SSD adapter is bad or incompatible if you are using an M.2 SSD, or the third party SSD is bad or incompatible. There is a slim possibility of a Logic Board failure, but the SSD (and adapter if used) are usually the weakest link all things being equal (assuming no accidental damage to the Logic Board).
From reading these forums for years now.....the most compatible and reliable M.2 SSD Adapter appears to be from Sintech. That would be the only one I would use if I were to use an M.2 SSD in a Mac.
If a Sintech SSD adapter does not help, then most likely it is an issue with the M.2 SSD itself. Not all SSDs are compatible with all computers. Or maybe the SSD is failing.
If you have an OWC SSD, then contact OWC tech support for assistance.