I am trying to download file from src folder in my react app, but file download is failing
file import
import test from "../../test.json";
download
const link = document.createElement("a");
link.href = test;
link.setAttribute("download", `test.json`);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
You can not download files in the src folder. If you need this file and change it in every build, you can use a script and run it before building for copying files from src to the public folder. If not, you must copy the file to the public folder.