-
Notifications
You must be signed in to change notification settings - Fork 282
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
Window is not defined for preact pre-render #485
Comments
…orm-data/form-data#485) (#54) Co-authored-by: aemaem <michael.mair@leftshift.one>
…orm-data/form-data#485) (#54) Co-authored-by: aemaem <michael.mair@leftshift.one> (cherry picked from commit 8ed0326)
Getting the same error on version 3.0.0 when performing SSR. Updating browser.js to this solves the problem but it would be good is this was shipped. /* eslint-env browser */
module.exports = typeof self == 'object' ? self.FormData : typeof window !='undefined' ? window.FormData : undefined; Since the SSR does not have a window-object we need to check that it exists, no requests are performed on the server but the rendering will complain about this use of the window-variable. PR Created: #496 |
This updates that browser.js does not throw when rendering on the server and window is not defined. Solves issue form-data#485
For me, this was caused by the
I fixed this by defining I'm using
This won't be relevant for everyone but hopefully provides a clue. |
Preact pre-render throws an error because window doesn't exist on the render environment :
`
/node_modules/form-data/lib/browser.js
ReferenceError: window is not defined`
`
This is most likely caused by using DOM or Web APIs.
Pre-render runs in node and has no access to globals available in browsers.
Consider wrapping code producing error in: 'if (typeof window !== "undefined") { ... }'
`
I could use the --no-prerender tag on the build command but I really didn't want to use it, is there a work-a-round for this? or should I create a pull-request to add "if (typeof window !== "undefined")..." ?
The text was updated successfully, but these errors were encountered: