-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix error in server-side rendering (SSR) #2039
Conversation
Is there any expected merge date for this? |
@niklasvh could you merge this one 🙏 |
@gorkemyontem @thomasMary FYI you can use e.g. the awesome |
hi @niklasvh, I can confirm that this fix seems to work, but it's hasn't been published to npm yet. anyway we can get it in npm soon? thanks! |
This answer worked for me: https://stackoverflow.com/a/59540525/90257 |
Is this up on npm yet? |
It seems not, any idea how to fix this error? |
Hello everyone! An error occurs with server side rendering (the window is not defined), how can I update npm module from this pull ? In the released version v1.0.0-rc.5, there is no this update, it is insanely important for our project! |
I updated it manually in html2canvas.js and changed it from: and that worked, at least for me |
You might want to take a look at dynamic imports with no ssr:
https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr
…On Thu, May 14, 2020 at 8:30 PM esteban89 ***@***.***> wrote:
Hello everyone! An error occurs with server side rendering (the window is
not defined), how can I update npm module from this pull ?
In the released version v1.0.0-rc.5, there is no this update, it is
insanely important for our project!
@Livven <https://github.com/Livven>
I updated it manually in html2canvas.js and changed it from:
CacheStorage.setContext(window);
to
if (typeof window !== "undefined") { CacheStorage.setContext(window); }
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2039 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFD33BVXE2QVAW5XDGFWZ3RRR5KPANCNFSM4JB3W7DA>
.
|
Thx for your reply! You edit this in node_modules folder ? Or you load the html2canvas script directly in project folder without npm and edit them ? |
Thx for your reply! In suddenly, i don't use Next.js, in project we use Gatsby.js. I use this method, but it not working for me :( |
Yes I edited it in node_modules folder |
Hi @esteban89 @worteepz, for nextjs, If you remove your import:
Usage:
Hope it Helps 🙏 I have not tested html2canvas library but some other library which causing the same > ReferenceError: window is not defined error in my nextjs project. |
@niklasvh any plans to release this fix on npm? |
Please bump to new version |
Summary
This PR fixes/implements the following bugs/features
html2canvas
causes JavaScript applications that use server-side rendering (e.g. via Next.js, Nuxt, Gatsby, Gridsome) to break as theCacheStorage.setContext(window)
call that is executed on import tries to access thewindow
variable that does not exist in Node.Obviously, this won't fix the actual functionality of taking a screenshot in Node, but it will allow for apps that use SRR to be pre-rendered on the server and then delivered to the client, where it will then be possible to use this library take screenshots.
Test plan (required)
Code formatting
Closing issues
Fixes #