react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation

Open santrajyadav196 opened this issue 9 months ago • 6 comments

I am using @react-pdf/renderer which version is 2.1.0. I was using this packing last 1.5years but i wasn't facing this issue but now i am facing this issue in node version from 14 to 16. I am using react which version is 16.14. The above errors is due font font is not compiling. Earlier it was working. Pls suggest me what should i do so that font works using Font.register() method.

Thanks in advance.

santrajyadav196 avatar Mar 03 '25 09:03 santrajyadav196

same issue with this version as well 3.1.13

rajesh-ss avatar Mar 03 '25 09:03 rajesh-ss

I'm using Font.register just fine in site docs and examples here. I'll need more data on how to reproduce

diegomura avatar Mar 03 '25 14:03 diegomura

@diegomura pls use react-pdf/renderer 2.1.0, then you cant not use Font.register to register new font which is external. I am using react 16.14 and react-pdf-render 2.1.0

santrajyadav196 avatar Mar 03 '25 14:03 santrajyadav196

@santrajyadav196 Did you get the solution? I'm also facing the same issue.

ManiRkandan avatar Mar 28 '25 09:03 ManiRkandan

My project runs fine locally but also facing the same issue after being packaged with Docker, adding this command in the Dockerfile, after npm i and before npm run build helps fix this error:

RUN find node_modules/@react-pdf -type f -name '*.js' -exec sed -i 's/fetch__default\["default"\](/(typeof fetch === "function" ? fetch : require("cross-fetch"))(/g' {} +

AnhTuan-AiT avatar Jun 18 '25 08:06 AnhTuan-AiT

Anyone have a definitive solution?

deivsonbf avatar Aug 21 '25 22:08 deivsonbf