-
-
Notifications
You must be signed in to change notification settings - Fork 882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server Error TypeError: url.replace is not a function #1554
Comments
I am having an issue with setting up the web worker as well when testing in Jest. I receive this error: |
@BlankTurbo You didn't give me too many info to work with, but if I have to guess, you're trying to render React-PDF on the server side which doesn't make a lot of sense, because you can't stream canvas over the network anyway. |
@vdo9 If you're using ESM modules, I'd discourage you from using Jest altogether. It has numerous problems with ESM modules handling. Personally, I was not able to make it work well for my use case and have decided to move on to more modern Vitest. Migrating multiple repositories took me less time than trying to debug Jest bugs in one. Alternatively, you could:
|
@wojtekmaj I am using a monorepo, my node_modules where my react-pdf and pdfjs-dist file are, not in the folder in which I am working, When I am using a cdn it is working completely fine but when I am approaching it as per the documentation method to use it from my node_modules rather than using the cdn then the props which I am passing in the new URL(x, y) are not able to make a proper url out of it, and we are giving it to a string it is throwing the error that I wanted to basically know if there can be a different approach to this? As you correctly mentioned that we can't stream canvas over the network anyway, but we somehow send images and svg files right over the server and user it in out web-app, So if there is any way to do the same with the Browser : Chrome Version 114.0.5735.198 (Official Build) (arm64) My |
If you manually copied the file over and it's still giving you |
Found out the solution using this approach Thanks a lot! |
I have one more issue which I faced recently not that big, that I will raise it in another issue, tagging it here only. When I was using react-pdf 6.2.2 version my code was working perfectly fine, recently when I updated my version to 7.1.2 it is not working on deployment. What error it is showing on AWS Amplify is |
Seems related to #1504. The direct cause appears to be pdfjs-dist update. These are always fun. |
Could you please share the solution, What you did? I am still unable to figure it out. I am also facing the same issue. |
@praveengoswami1996 Just use the correct file location it will work. For me when I did it like this It worked because the location of my For me it worked like this because I use a monorepo and node_modules are hoisted and they were not inside my root folder. So do check the location of file Try this your issue should get resolved. |
Thanks Ashwin!! I appreciate your response. It perfectly worked for me. Thanks alot. |
problem statement like this because next js can not render outside of i just wrap pdf.js config in app tsx like this and problem fix |
A better idea than useEffect appears to be: if (typeof window !== 'undefined') {
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.js',
import.meta.url,
).toString();
} This would prevent the code from running on the server, while still running before render on the client. |
Before you start - checklist
Description
Steps to reproduce
Simply I have just added the code and when I am refreshing my development environment it is throwing this error.
Expected behavior
As per the documentation this code should work but it is throwing error.
Actual behavior
It should not throw the error as it does not when we use cdn.
Additional information
No response
Environment
The text was updated successfully, but these errors were encountered: