Do you use a personal OneDrive or OneDrive for Business?
If it is OneDrive for Business, then this issue can be caused by OneDrive account permissions. According to OneDrive documentation:
"Note: You can only get shareable links for files in OneDrive for Business if the user's tenant admin has enabled external sharing."
So, please whether check, or ask your OneDrive's administrator to check, if external sharing is enabled at https://admin.onedrive.com/?v=SharingSettings.