The error message "FormData parsing error: final boundary is missing" appears due

Recently, I made the switch from node to bun in a Next.js project. However, when trying to parse form data, I encountered this error:

14 | const POST = async (request)=>{
15 |     try {
16 |         console.log("request: ", await request.headers);
17 |         const formData = await request.formData();
                                    ^
TypeError: FormData parse error missing final boundary
      at processTicksAndRejections (:61:77)

After some research, it seems that this error can occur if the Content-Type is mistakenly overwritten during fetch requests. But in my case, that doesn't seem to be happening. The following snippet shows the form component triggering the POST:

  /// ...
  return (
    <form
      action={action}
      method="post"
      className="mt-4"
      onSubmit={async (e) => {
        e.preventDefault();
        setLoading(true);
        setErrors(null);
        const formData = new FormData(e.currentTarget);
        const response = await fetch(action, {
          method: "POST",
          body: formData,
          redirect: "manual",
        });

        if (response.status === 0) {
          // redirected
          // when using `redirect: "manual"`, response status 0 is returned
          return router.refresh();
        }
        setErrors(await response.json());
        setLoading(false);
      }}
    >);

The header also correctly displays the Content-Type:

request:  Headers {
  "host": "localhost:3000",
  "accept": "*/*",
  "accept-language": "en-GB,en;q=0.9",
  "accept-encoding": "gzip, deflate",
  "sec-fetch-mode": "cors",
  "content-type": "multipart/form-data; boundary=----WebKitFormBoundary2sBEsUtE1u6eArLT",
  "origin": "http://localhost:3000",
  "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
  "referer": "http://localhost:3000/sign-up",
  "content-length": "244",
  "connection": "keep-alive",
  "sec-fetch-dest": "empty",
  "sec-fetch-site": "same-origin",
  "x-forwarded-host": "localhost:3000",
  "x-forwarded-port": "3000",
  "x-forwarded-proto": "http",
}

The backend code appears to be standard as well:

// ...
export const POST = async (request: Request) => {
  try {
    console.log('request: ', await request.headers)
    const formData = await request.formData();
    // console.log('request form data: ', JSON.stringify(request));
    const username = formData.get("username");
    const password = formData.get("password");
// ...

Your assistance would be greatly appreciated!

Answer №1

After some investigation, it became clear that the issue lies within the bun software itself. The solution was to completely replace bun with node, which successfully resolved the problem. For more details, check out https://github.com/oven-sh/bun/issues/2644.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Running multiple node versions at the same time with nvm-windows: A step-by-step guide

Problem: Our challenge is to run and utilize two different node versions - 14 and 12, concurrently for two separate applications in order to support the execution of npm run dev and npm install commands with the correct version as required. What we have at ...

Is there a way for my React app to display a 404 error page for a non-existent document?

Hey there! I recently submitted my website to a search engine, but encountered an error stating "Your non-existing pages don't return status 404". I'm not sure how to go about returning this status. I've been trying to solve this issue, but ...

Acquire the URL using Angular within a local environment

I am currently working on a basic Angular project where I have a JSON file containing some data. [{ "name": "Little Collins", "area": "Bronx", "city": "New York", "coverImage": "https://images.unsplash.com/photo-1576808597967-93bd9aaa6bae?ixlib=rb-1.2.1&a ...

Updating the value of a different key within the same object using React Formik's setFieldValue方法

My objective is to automatically select a value in an option select when the onChange event occurs, and then use setFieldValue to set values for 2 Fields with key-value pairs within the same object. The issue I'm facing: Why does calling setFieldValu ...

Leveraging UseParams for Detailed Product Pages

I am in the process of developing a product detail page using the useParams Hook in my ReactJS application. Unfortunately, I have encountered some issues as I am able to retrieve the ID from the URL but unable to fetch the item's title, image, and pri ...

What are some strategies for ensuring that the API call waits for the necessary data to be retrieved?

Currently, I am working with React Native and Redux. The initial state of Redux includes emailExists being set to null: const INITIAL_STATE = { // ... emailExists: null, }; During user registration, I first check if the user already exists by sending ...

Stop Material UI Typography Text from exceeding the boundaries of its parent container

I am dealing with a situation where I have a Typography element nested inside a div, and the issue arises when the text within the Typography element is too lengthy causing it to overflow outside the boundaries of its parent div. This behavior is not desir ...

Performing an ASync call to the GetData routine in MongoClient using NodeJS

Combining code snippets from https://www.w3schools.com/nodejs/nodejs_mongodb_find.asp and https://stackoverflow.com/questions/49982058/how-to-call-an-async-function#:~:text=Putting%20the%20async%20keyword%20before,a%20promise%20to%20be%20resolved. Upon ob ...

Guide to encapsulating a container within a map function using a condition in JSX and TypeScript

Currently, I am working with an array of objects that are being processed by a .map() function. Within this process, I have a specific condition in mind - if the index of the object is greater than 1, it should be enclosed within a div element with a parti ...

Error: The initial parameter must be a string, Buffer, ArrayBuffer, Array, or Array-like Object. An object type was passed in instead in CryptoJS

In my quest to encrypt and decrypt data in react-native, I embarked on using the crypto node module by incorporating it into my react native project through browserify. While attempting encryption with the code snippet provided below, an error surfaces sta ...

Utilizing the Google Site Verification API through a Firebase cloud function

I am attempting to utilize the Google Site Verification API from a Firebase function using Node.js. The README found in the google-api-nodejs-client repository on Github advises using the default application method over manually creating an OAuth2 client, ...

The reducer I have is inexplicably returning undefined even though I'm certain it was added to combineReducers

After countless hours of debugging, everything seems to be in working order but the problem still persists. The main reducer file is located at reducers/index.js // @flow import { combineReducers } from "redux"; import blocks from "./blocks"; import user ...

Pressing the button does not switch the component state (when the button and component are located in separate files)

Here is the code snippet of my layout: import Menu from "./Menu"; import ButtonMenu from "./ButtonMenu"; export default function RootLayout({ children, }: { children: React.ReactNode; }) { return ( <html lang="en" ...

Utilizing ReactJs refs to set focus on an input element

Exploring the use of refs in ReactJs to focus a textbox from a button click. Encountering the following error message: bundle.js:114 Uncaught TypeError: Cannot read property 'focus' of undefined Check out the Source Code below: class FocusTex ...

Incorporating conditional statements within a loop

I'm racking my brains over this issue, can you lend a hand? Currently, I am extracting data from a website. The .MyElement containers on the site store either gif or jpg URLs that I need to retrieve. In my node.js app, I am utilizing a Cheerio-base ...

Learn how to manage Ajax GET/POST requests using nodejs, expressjs, and Jade Template Engine

I am currently working on a project that involves the use of NODE, EXPRESS, and JADE TEMPLATE ENGINE, as well as AJAX to optimize page loading. However, I encountered an issue when trying to utilize the data received from a GET request in AJAX directly wit ...

What is the trick to make the "@" alias function in a Typescript ESM project?

My current challenge involves running a script using ESM: ts-node --esm -r tsconfig-paths/register -T src/server/api/jobs/index.ts Despite my efforts, the script seems unable to handle imports like import '@/server/init.ts': CustomError: Cannot ...

Creating interactive avatars with Material UI and React to provide a dynamic user

I have developed a simple form validation application using react.js. Each user has a unique profile containing their personal information. I am looking to utilize the first letter of the user's name, for example Peter, where the letter "P" would be d ...

Choosing the Right SQLite Library for Node.js

Currently, I am in the process of developing an application using node.js. For the embedded database functionality, I have decided to use SQLite. After exploring various npm modules for SQLite, I came across a few options: https://github.com/grumdrig/nod ...

Mongoose reverse population involves querying a document's references

I am currently exploring ways to populate my business orders using the businessId property in my orders collection. I attempted a solution but I am facing difficulties making it work. https://www.npmjs.com/package/mongoose-reverse-populate If you have an ...