question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
sergiodxacommented, Sep 5, 2022

@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.

0reactions
RotrixLOLcommented, Dec 11, 2022

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Technical Explanation - Remix
Technical Explanation. This document hopes to answer the question: "What is Remix?" Remix is four things: A compiler; A server side HTTP handler;...
Read more >
Remix Run - fetch returning empty response - Stack Overflow
I am pretty new to Remix and am running it with an express server backend. I have the following routes setup: routes ->...
Read more >
How to validate forms in Remix - LogRocket Blog
Remix takes a different approach from React when it comes to ... a POST request containing the form data to the server using...
Read more >
Implementing Strapi v4 Authentication with Remix
In this article, we'll create a Remix application with authentication and authorization using... Tagged with strapi, remix, javascript, ...
Read more >
Strapi v4 Authentication with Remix - Medium
The “Remix App Server” is a full-featured Node.js server based on Express. ... You can get it from GitHub and use it to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found