vpjmV
tRPC10mo ago
13 replies
vpjm

FormData TRPCClientError

Hi i have this error in my client :
createFormControl.ts:1217 Uncaught (in promise) TRPCClientError: [
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "undefined",
    "path": [
      "url"
    ],
    "message": "Required"
  },
  {
    "code": "custom",
    "message": "Input not instance of File",
    "fatal": true,
    "path": [
      "file"
    ]
  }
]
    at TRPCClientError.from (TRPCClientError.mjs:48:20)
    at httpBatchStreamLink.mjs:118:56
I am working with Next 15.2.2 and tRPC 11.0.0-rc.682. NO MATTER what I try, FormData cannot be sent to my server — this is very frustrating. If anybody has encountered this problem, please help me!

I have a smaller project with the exact same uploading form, and it works fine there (even with latest next version) . I don’t know how to debug this — I’ve spent hours and haven’t found any major differences between the codebases.

//DATA TRANSFORMER src: https://github.com/juliangra/trpc-next-formdata-app-router
interface DataTransformer {
  serialize: (object: any) => any
  deserialize: (object: any) => any
}

export class FormDataTransformer implements DataTransformer {
  serialize(object: any) {
    if (!(object instanceof FormData)) {
      throw new Error('Expected FormData')
    }

    return object
  }

  deserialize(object: any) {
    return object as JSON
  }
}
Was this page helpful?