[Expo + UT] Error when importing @uploadthing/expo

Hey, I am building an expo app and I am getting this error when importing the package (only on native, web works fine)
Property 'TextDecoder' doesn't exist
Property 'TextDecoder' doesn't exist
SDK versions:
"@uploadthing/expo": "7.0.4-canary.8bc74c6",
"uploadthing": "7.1.1-canary.8bc74c6",
"@uploadthing/expo": "7.0.4-canary.8bc74c6",
"uploadthing": "7.1.1-canary.8bc74c6",
Attaching my stacktrace from sentry (raw and a screenshot). I looked at the SDK source and found that the only place where TextDecoder is used is packages/uploadthing/src/internal/shared-schemas.ts Help appreciated 🙂
27 Replies
markr
markr•2mo ago
I think RN doesn’t have TextDecoder natively, you need to polyfill it eg expo install @bacons/text-decoder Cc @julius - RN + effect might be somewhat problematic
julius
julius•2mo ago
expo 52 will have text-decoder ootb but until then you just need a polyfill
julius
julius•2mo ago
there is an issue though which i've half fixed here: https://github.com/pingdotgg/uploadthing/pull/1013 but still not entiery fixed. my guess it's RNs weird blob implementation
GitHub
fix: @uploadthing/mime-types exports not supported in Expo by jul...
Closes #999 flatten export paths since Expo doesn't resolve exports condition by default. This is similar to what we do for the main uploadthing package which has multiple entrypoints as w...
markr
markr•2mo ago
They’re using the canary from that PR
sudhanshug
sudhanshugOP•2mo ago
I was able to get it to not error out using a polyfill (text-encoding-polyfill). But then my uploads are failing with
[(MicroCause.Fail) UploadThingError: Failed to report event "upload" to UploadThing server]
[(MicroCause.Fail) UploadThingError: Failed to report event "upload" to UploadThing server]
This error may or may not be related The SDK does not even call my /api/uploadthing endpoint. However, the same setup works fine on the web export of the app
markr
markr•2mo ago
Can you get the error.cause when it fails with that error?
sudhanshug
sudhanshugOP•2mo ago
That was a false alarm, I did not setup port forwarding correctly on my device - the host wasn't found hence no requests. But now I am getting the error "UPLOAD_FAILED" (code and message is the same) with undefined err.cause. The upload action to my /api/uploadthing API resolves to a 200 response so I am assuming it is failing to upload to the signed URL. (trying to confirm this assumption)
markr
markr•2mo ago
Can you enable debug logs on the server side to see where it is getting hung up on more detail?
julius
julius•2mo ago
I’ll take a look and revive the PR later today. Last time I tried it everything seemingly worked except no bytes were uploaded to UT (file said uploaded and 0B on the dash)
sudhanshug
sudhanshugOP•2mo ago
Okay so I did some digging and here is what's happening: 1. My /api/uploadthing api resolves with the correct presigned url 2. UT sdk makes a HEAD request to the signed URL which succeeds (which is 0B in size) 3. SDK errors out with the error I shared earlier ("UPLOAD_FAILED"). It never sends the PUT/POST request with the actual file. Here is the signed URL: https://sea1.ingest.uploadthing.com/VeWg9249ETbUVe0a0y49ETbU4LmjuWZpgvsiNy20cadl56Io?expires=1730807221847&x-ut-identifier=72uz6xz82c&x-ut-file-name=047f9be7-7e94-4e95-9008-f12e5fb3d9bd.jpeg&x-ut-file-size=243608&x-ut-file-type=image%2Fjpeg&x-ut-slug=videoAndImage&x-ut-custom-id=wf9i4suwqj5b4hkvxkule5x5w6jg&x-ut-content-disposition=inline&x-ut-acl=public-read&signature=hmac-sha256=24f46a6c19b09d606e63aff002f29376ec47d165c9658a1315eb3e93131ebf10
julius
julius•2mo ago
just got home from school will start to investigate this now
sudhanshug
sudhanshugOP•2mo ago
🙌
julius
julius•2mo ago
@sudhanshug this is how our example works from the PR that fixes the mime-type exports resolution no errors, just doesn't get any data. what are you doing to make it error?
sudhanshug
sudhanshugOP•2mo ago
Can you try jsdebugger’s network tab and see if your upload request resolves. I only see a HEAD request
julius
julius•2mo ago
yea it's sending the PUT
No description
julius
julius•2mo ago
looks empty for sure 😦
No description
julius
julius•2mo ago
problem definetely feels like it's due to RNs stupid blob implementation not being sliceable
sudhanshug
sudhanshugOP•2mo ago
npm
react-native-blob-util
A module provides upload, download, and files access API. Supports file stream read/write for process large files.. Latest version: 0.19.11, last published: 3 months ago. Start using react-native-blob-util in your project by running npm i react-native-blob-util. There are 65 other projects in the npm registry using react-native-blob-util.
julius
julius•2mo ago
looking at that now there's like 3 levels of forks to have a maintained one though 😅
sudhanshug
sudhanshugOP•2mo ago
i wrote this a few days ago to do direct uploads to s3 via activestorage
sudhanshug
sudhanshugOP•2mo ago
maybe it's of use to you lol, maybe not
julius
julius•2mo ago
i have it working without resumability
sudhanshug
sudhanshugOP•2mo ago
can you cut me an adhoc build lol, my users are kinda stuck 🙃 good for me, they are our contractors and I can direct them to the web app but not ideal 🙂
julius
julius•2mo ago
building pnpm add @uploadthing/[email protected] [email protected]
Avinash
Avinash•2mo ago
Hello, Im having the same issue TextDecode How to fix it? btw in installed the above canary version
Avinash
Avinash•2mo ago
this is what im getting when api route triggered
No description
julius
julius•2mo ago
Expo 52 should have both encoder and decoder built-in but before then you need to use a polyfill. what version of expo/expo-image-picker?
Want results from more Discord servers?
Add your server