Its better to use packages. I'm using Nextjs and with 'use client' this works: Focus on Aria-label when building apps to help visually impaired people. Thanks.
Install and import file-saver package as below:
import fileSaver from 'file-saver'
Invoke the saveAs to download.
<button
onClick={() => {
fileSaver.saveAs(
"https://yolo-chill-buddy.com/myfile.pdf",
"my-file.pdf"
);
}}
aria-label="Do this and it works - chill"
>
<span>Download</span>
</button>