From 3320270856374413de8c4218b9418f0b65de5d6e Mon Sep 17 00:00:00 2001 From: HamzaNa1 Date: Thu, 25 Sep 2025 12:29:20 +0300 Subject: [PATCH 1/2] fix url creation --- packages/expo/src/index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/expo/src/index.ts b/packages/expo/src/index.ts index d1ff6a81bc..1518790997 100644 --- a/packages/expo/src/index.ts +++ b/packages/expo/src/index.ts @@ -16,9 +16,9 @@ export interface GenerateTypedHelpersOptions { * @example "/api/uploadthing" * @example "https://www.example.com/api/uploadthing" * - * If relative, host will be inferred from either the `EXPO_PUBLIC_SERVER_ORIGIN` environment variable or `ExpoConstants.hostUri` + * If relative, host will be inferred from either the `EXPO_PUBLIC_SERVER_URL` environment variable or `ExpoConstants.hostUri` * - * @default (process.env.EXPO_PUBLIC_SERVER_ORIGIN ?? ExpoConstants.debuggerHost) + "/api/uploadthing" + * @default (process.env.EXPO_PUBLIC_SERVER_URL ?? ExpoConstants.debuggerHost) + "/api/uploadthing" */ url?: URL | string; /** @@ -55,17 +55,18 @@ export const generateReactNativeHelpers = ( 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}`), + initOpts?.url ?? "/api/uploadthing", + process.env.EXPO_PUBLIC_SERVER_URL ?? + (typeof window !== "undefined" && window.location?.origin + ? window.location?.origin + : `http://${debuggerHost}`), ); } catch (err) { // Can't throw since window.location is undefined in Metro pass // but may get defined when app mounts. // eslint-disable-next-line no-console 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.`, + `Failed to resolve URL from ${initOpts?.url?.toString()} and ${process.env.EXPO_PUBLIC_SERVER_URL} or ${debuggerHost}. Your application may not work as expected.`, err, ); } From 3f65cee9c2200f08b1b1d6b7565157521f80f862 Mon Sep 17 00:00:00 2001 From: "Mark R. Florkowski" Date: Wed, 15 Oct 2025 17:18:07 -0700 Subject: [PATCH 2/2] Add changeset --- .changeset/tough-files-leave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-files-leave.md diff --git a/.changeset/tough-files-leave.md b/.changeset/tough-files-leave.md new file mode 100644 index 0000000000..393bdd2cd0 --- /dev/null +++ b/.changeset/tough-files-leave.md @@ -0,0 +1,5 @@ +--- +"@uploadthing/expo": patch +--- + +Fix URL construction - Previously the code checked if window.location is defined, which threw an error because window did not exist, this caused it to fallback to the default URL without checking the env variable The new code will check if the env variable FIRST and use it if it exists, then check safely for the window and then for the debuggerHost