workshoptech/discourse-js

FormData is not defined

Closed this issue · 3 comments

Trying to do a simple posts.create (specifying only category and raw), but getting the following error:

UnhandledPromiseRejectionWarning: ReferenceError: FormData is not defined
    at createBody

What's the solution for this error? How is this fixed. Still getting this for a simple post.create per the original issue.

Hello,

I apologize if this answer is not helpful; I didn't retain notes from this particular issue when it happened. The reason I immediately closed the ticket shortly after opening it was because I realized FormData is part of the standard API for web browsers. I was trying to interface with Discourse API through a chatbot (browserless), so FormData was not available. I ended up writing my own wrapper for my purposes, so did not use discourse-js in the end.

Hi, no problem. Thanks for the update. We were doing the same thing - interfacing with Discourse via the browser and I realized this too. Actually, you can install FormData for the server also via a package, but that's not the way discourse-js is set up unfortunately. What's strange is doing discourse in the browser is not safe because then your API key is visible in the browser. So I'm not sure why they did the package this way. In any case, the package is a great starter.