# Error: Server Action failed to parse FormData: unexpected end of data

- **ID:** `nextjs/server-action-formdata-parse-fail`
- **Domain:** nextjs
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The FormData sent to a Server Action is incomplete or malformed, often due to a client-side fetch or form submission that truncates the body before sending.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| next@14.2.0 | active | — | — |
| next@14.2.5 | active | — | — |
| next@15.0.0-rc.1 | active | — | — |

## Workarounds

1. **Ensure the client-side form submission uses the native FormData API correctly. For fetch, avoid manually setting headers: `const formData = new FormData(); formData.append('field', value); await fetch('/api/action', { method: 'POST', body: formData });`** (85% success)
   ```
   Ensure the client-side form submission uses the native FormData API correctly. For fetch, avoid manually setting headers: `const formData = new FormData(); formData.append('field', value); await fetch('/api/action', { method: 'POST', body: formData });`
   ```
2. **Validate the FormData before sending by logging or checking entries: `for (let [key, value] of formData.entries()) { console.log(key, value); }` to confirm all fields are present.** (75% success)
   ```
   Validate the FormData before sending by logging or checking entries: `for (let [key, value] of formData.entries()) { console.log(key, value); }` to confirm all fields are present.
   ```
3. **If using a custom fetch, ensure no premature stream closing. Use `await fetch(url, { method: 'POST', body: formData })` without wrapping in JSON.stringify.** (80% success)
   ```
   If using a custom fetch, ensure no premature stream closing. Use `await fetch(url, { method: 'POST', body: formData })` without wrapping in JSON.stringify.
   ```

## Dead Ends

- **Adding 'Content-Type: multipart/form-data' header manually in fetch calls** — The browser automatically sets the correct Content-Type with boundary for FormData; manually setting it can break parsing. (70% fail)
- **Increasing server body parser size limit in next.config.js** — The error is not about size limits but about incomplete data transmission, often due to client-side logic errors. (50% fail)
- **Switching to JSON.stringify instead of FormData for the request body** — Server Actions expect FormData for 'use server' functions; sending JSON requires different handling and may cause type mismatches. (60% fail)
