Hi @parwaze sadool ,
Whether other files (such as .doc or .exe) will occur the same issue?
I couldn't reproduce your issue per my test, I can open .txt file and .js file correctly in SharePoint document library.
Try to delete the current file, upload again to check if you could open it successfully.
If the issue still exists, please create a brand new document library then upload these files to compare the result.
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.