tRPCttRPC
Powered by
vpjmV
tRPC•12mo 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
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
  }
}
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
  }
}
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Unhandled runtime TRPCClientError
Answer OverflowAAnswer Overflow / ❓-help
3y ago
TRPCClientError: fetch failed
koko#1337Kkoko#1337 / ❓-help
3y ago
Examples-next-formdata
leonLleon / ❓-help
2y ago
File upload with formdata
YsqanderYYsqander / ❓-help
2y ago