From 7c79ee934d37876cc4c8af01009d11141c3adf98 Mon Sep 17 00:00:00 2001 From: reallybeard <89934888+reallybeard@users.noreply.github.com> Date: Tue, 4 Aug 2026 11:38:38 -0500 Subject: [PATCH 1/2] fix(swap-widget): guard import.meta.env so non-Vite bundlers can import the widget `import.meta.env` is only defined once a Vite-style bundler substitutes it. webpack, Turbopack and Rollup evaluate the module with it still undefined, and the existing `??` guards the property rather than the object, so reading `.VITE_SWAP_WIDGET_API_URL` throws at module evaluation and takes down the importing tree. Optional chaining keeps Vite behaviour identical while letting every other bundler fall back to the documented default base URL. Co-authored-by: Cursor --- packages/swap-widget/src/api/client.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/swap-widget/src/api/client.ts b/packages/swap-widget/src/api/client.ts index d4df7e4383e..8aa6a5d0b04 100644 --- a/packages/swap-widget/src/api/client.ts +++ b/packages/swap-widget/src/api/client.ts @@ -1,7 +1,10 @@ import type { AssetId, AssetsResponse, QuoteResponse, RatesResponse } from '../types' +// `import.meta.env` only exists once a Vite-style bundler substitutes it. Consumers on webpack, +// Turbopack or Rollup evaluate this module with it still undefined, so reading the property +// directly throws before the `??` fallback can apply and takes the whole widget down on import. const DEFAULT_API_BASE_URL = - import.meta.env.VITE_SWAP_WIDGET_API_URL ?? 'https://api.shapeshift.com' + import.meta.env?.VITE_SWAP_WIDGET_API_URL ?? 'https://api.shapeshift.com' export type ApiClientConfig = { baseUrl?: string From 7b71368f810bf790ef7f71281d004a896ab23195 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Tue, 4 Aug 2026 16:58:01 -0600 Subject: [PATCH 2/2] fix(swap-widget): remove import.meta.env from published code entirely Hardcode the documented default API base URL in the library and move the VITE_SWAP_WIDGET_API_URL read into the Vite demo apps, which pass it via the existing apiBaseUrl prop. The published bundle now contains no env reads at all, so it works under any bundler without guards. Co-Authored-By: Claude Fable 5 --- packages/swap-widget/src/api/client.ts | 6 +----- packages/swap-widget/src/demo/ExternalWalletApp.tsx | 2 ++ packages/swap-widget/src/demo/InternalWalletApp.tsx | 2 ++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/swap-widget/src/api/client.ts b/packages/swap-widget/src/api/client.ts index 8aa6a5d0b04..352a3aa00ee 100644 --- a/packages/swap-widget/src/api/client.ts +++ b/packages/swap-widget/src/api/client.ts @@ -1,10 +1,6 @@ import type { AssetId, AssetsResponse, QuoteResponse, RatesResponse } from '../types' -// `import.meta.env` only exists once a Vite-style bundler substitutes it. Consumers on webpack, -// Turbopack or Rollup evaluate this module with it still undefined, so reading the property -// directly throws before the `??` fallback can apply and takes the whole widget down on import. -const DEFAULT_API_BASE_URL = - import.meta.env?.VITE_SWAP_WIDGET_API_URL ?? 'https://api.shapeshift.com' +const DEFAULT_API_BASE_URL = 'https://api.shapeshift.com' export type ApiClientConfig = { baseUrl?: string diff --git a/packages/swap-widget/src/demo/ExternalWalletApp.tsx b/packages/swap-widget/src/demo/ExternalWalletApp.tsx index dd2c42ec65e..df1afd977a7 100644 --- a/packages/swap-widget/src/demo/ExternalWalletApp.tsx +++ b/packages/swap-widget/src/demo/ExternalWalletApp.tsx @@ -31,6 +31,7 @@ import { DemoCustomizer, useDemoTheme } from './DemoCustomizer' import { WidgetModal } from './WidgetModal' const PROJECT_ID = import.meta.env.VITE_WALLETCONNECT_PROJECT_ID +const API_BASE_URL = import.meta.env.VITE_SWAP_WIDGET_API_URL if (!PROJECT_ID) throw new Error('VITE_WALLETCONNECT_PROJECT_ID is not set') @@ -102,6 +103,7 @@ const ExternalDemoBody = ({ theme, setTheme }: ExternalDemoBodyProps) => { const widget = useMemo( () => ( { const widget = useMemo( () => (