remix: `request.formData()` fails when using an express server with remix

What version of Remix are you using?

latest

Steps to Reproduce

  1. setup express server to use with remix with express.urlencoded() and express.json()
  2. create a basic form with an ActionFunction to view the formdata

Expected Behavior

request.formData() returns the data that was submitted to the form.

Actual Behavior

formdata is empty when using an express server, since express requests don’t conform to the fetch api.

While I will admit that this is perhaps not a bug, I do think that since we assume that all requests (at least in ActionFunctions) conform to the fetch api that request.formData() should work? However, this could be a feature request rather than a bug.

A possible solution is to adjust the createRequestHandler for express to add formdata?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 17 (2 by maintainers)

Most upvoted comments

@khowling request.formData() works regardless of the server and you don’t need to add any middleware to Express to make it work, actually if you add body-parser to Express it will stop working on Remix because the body of a request can only be read once.

Are you sure your FormData comes empty? If you did console.log(formData) and saw in your terminal this FormData {} as if it was an empty object, that’s expected, FormData is a data structure not a plain object, you need to do formData.get("the name of an input") to access the data.

@khowling request.formData() works regardless of the server and you don’t need to add any middleware to Express to make it work, actually if you add body-parser to Express it will stop working on Remix because the body of a request can only be read once.

Are you sure your FormData comes empty? If you did console.log(formData) and saw in your terminal this FormData {} as if it was an empty object, that’s expected, FormData is a data structure not a plain object, you need to do formData.get("the name of an input") to access the data.

Jeez, thank you very much!