serviejs / popsicle

Simple HTTP requests for node and the browser
MIT License
246 stars 19 forks source link

ReferenceError: FormData is not defined #101

Closed olivier-squid closed 7 years ago

olivier-squid commented 7 years ago

I got the error when using v9.1.0 within a node.js app.

blakeembrey commented 7 years ago

You shouldn't be referencing FormData in your own code, it only exists in browsers. You should use the popsicle.form() function to get back a FormData instance for use in browsers or node. If this is not what is happening, please provide more information about your setup and I can help more.

olivier-squid commented 7 years ago

Hi Blake,

first of all, thanks for your quick reply.

My problem probably comes from the fact that I using from my node app a js library aimed at being isomorphic which I build and which uses popsicle. My library works fine we used in a browser, but not from a node app. I you want to have a look my lib is here : https://github.com/openbouquet/bouquet-js

Thanks

blakeembrey commented 7 years ago

You shouldn't expect that a Webpack bundle works on node.js automatically. You should look at building the isomorphic app the same way I built popsicle - you can switch browser or node sources in package.json and publish like a regular node module, then you have your consumers bundle it. By bundling it for them, you're only bundling the browser-side popsicle and not the server-side interfaces. There's also a lot of other downsides from forcing the bundle of dependencies in your own package including the inability to dedupe, harder to minify, etc.

olivier-squid commented 7 years ago

Okay, makes sense, I'll check that. Thanks a lot