-
Notifications
You must be signed in to change notification settings - Fork 397
Description
Provide environment information
It is a monorepo so I ran the command only on the Expo app
System:
OS: macOS 15.6.1
CPU: (8) arm64 Apple M2
Memory: 454.17 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.local/state/fnm_multishells/49123_1757744526392/bin/node
npm: 10.9.2 - ~/.local/state/fnm_multishells/49123_1757744526392/bin/npm
pnpm: 9.0.0 - /opt/homebrew/bin/pnpm
bun: 1.2.21 - ~/.bun/bin/bun
Browsers:
Chrome: 140.0.7339.133
Safari: 18.6
npmPackages:
typescript: ^5.9.2 => 5.9.2
uploadthing: ^7.7.4 => 7.7.4Describe the bug
Whenever I upload I get Failed to parse response from UploadThing server after some debugging and going into the package's code I found out that in the generateReactNativeHelpers function it sets the default url to http://localhost:8081/api/uploadthing then tries to set it up which throws and catches an error, so it goes back to the default url which is not the one I set up in the env variable
The caught error is:
Failed to resolve URL from undefined and http://localhost:3000 or undefined. Your application may not work as expected. ReferenceError: window is not defined
Here's the code that causes the issue
let url = new URL("http://localhost:8081/api/uploadthing");
try {
url = new URL(initOpts?.url ?? "/api/uploadthing", typeof window.location !== "undefined" ? window.location.origin : process.env.EXPO_PUBLIC_SERVER_ORIGIN ?? `http://${debuggerHost}`);
} catch (err) {
console.warn(`Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_ORIGIN} or ${debuggerHost}. Your application may not work as expected.`, err);
}I fixed it by just replacing it with const url = new URL(${process.env.EXPO_PUBLIC_SERVER_ORIGIN}/api/uploadthing);
Also note that the env variable used in the code (EXPO_PUBLIC_SERVER_ORIGIN) is not the same one that the docs tells you to use
Link to reproduction
I don't think I can do a monorepo on stackblitz
To reproduce
-
Set up Expo as is in the docs
-
Try to use any of the functions that send requests to the server (in my case I was trying to upload images using
useImageUploaderhook) -
You get an error
Failed to resolve URL from undefined and http://localhost:3000 or undefined. Your application may not work as expected. ReferenceError: window is not defined
Additional information
I'm running the app using Expo 54.0.1 on a MacOS with an IOS Emulator
👨👧👦 Contributing
- 🙋♂️ Yes, I'd be down to file a PR fixing this bug!
Code of Conduct
- I agree to follow this project's Code of Conduct