I have a react component which I need to download a static file I have in an adjacent folder, I've tried loading the file using
import myFile from '../../myfile/myfile.pdf'
<Button onClick={(evt) => this.handleDownload(evt)}><a href={myFile} download="My_File.pdf">Temp Download BTN</a></Button>
but when I try to import that, it throws the error below
Cannot find module '../../myfile/myfile.pdf' or its corresponding type declarations.ts(2307)
CodePudding user response:
You should tell to typescript to resolve pdf files
Try to create file ../../myfile/index.d.ts
with the content
declare module "*.pdf" {
const value: any;
export = value;
}
CodePudding user response:
Add this to your declaration.d.ts
file in the root of the folder
declare module '*.pdf' {
const content: any;
export default content;
}