Skip to content
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

Upgrade to newer form-data SSR error #362

Closed
philosofonusus opened this issue Jun 16, 2022 · 4 comments
Closed

Upgrade to newer form-data SSR error #362

philosofonusus opened this issue Jun 16, 2022 · 4 comments

Comments

@philosofonusus
Copy link

I have an preact SSR application and when I try to build it preact build I recieve:

Unable to read file: /node_modules/graphql-request/node_modules/form-data/lib/browser.js

ReferenceError: window is not defined
method: oYKm

package form-data fixed this issue here form-data/form-data#496

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.

the solution to this is here, and they have added fix

module.exports = typeof self == 'object' ? self.FormData : typeof window !='undefined' ? window.FormData : undefined;

So please upgrade to newer version of form-data

@mrosata
Copy link

mrosata commented Mar 30, 2023

It would be nice not to include packages that write to the global object period. Easier said than done because it's not something one typically finds out about until things break.. but packages like this are often included in other packages, which causes a big old pain chain.

@mrosata
Copy link

mrosata commented Mar 30, 2023

@jasonkuhrt I ran

pnpm upgrade form-data@4.0.0
pnpm run test

locally and all the tests passed. Is it possible to make and release this change?

WesleyKapow added a commit to zeus-health/ctw-component-library that referenced this issue Mar 31, 2023
@WesleyKapow
Copy link

NOTE: form-data/form-data#496 has not been merged in yet.

I got this working by patching node_modules/form-data/lib/browser.js as shown in the above PR and using https://github.com/ds300/patch-package to create and apply the patch.

You can also override the form-data dependency via:

  "overrides": {
    "form-data": "4.0.0"
  },

But note, this isn't sufficient yet as form-data has yet to merge in the fix, thus the need for the patch!

mrosata pushed a commit to zeus-health/ctw-component-library that referenced this issue Mar 31, 2023
See
jasonkuhrt/graphql-request#362 (comment)

We're now forcing form-data to v4 AND providing the patch from
form-data/form-data#496. This fixes the issue
when trying to run this in SSR.
@jasonkuhrt
Copy link
Owner

Fixed by #501.

This was referenced Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants