Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

fix(vendor): replace removed react-router json helper and guard optimizeDeps (#1230)

Viktor Holik12444598f577
diff --git a/packages/core/src/migration-scripts/rename-default-store.ts b/packages/core/src/migration-scripts/rename-default-store.ts
deleted file mode 100644
index 5006cc82e..000000000
--- a/packages/core/src/migration-scripts/rename-default-store.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import { ExecArgs, IStoreModuleService } from "@medusajs/framework/types"
-import { Modules } from "@medusajs/framework/utils"
-
-const DEFAULT_STORE_NAME = "Medusa Store"
-const MERCUR_STORE_NAME = "Mercur Marketplace"
-
-export default async function renameDefaultStore({ container }: ExecArgs) {
- const storeService = container.resolve<IStoreModuleService>(Modules.STORE)
-
- const stores = await storeService.listStores({ name: DEFAULT_STORE_NAME })
-
- await storeService.updateStores(stores[0].id, { name: MERCUR_STORE_NAME })
-}
diff --git a/packages/dashboard-sdk/src/plugin.ts b/packages/dashboard-sdk/src/plugin.ts
index 6548bff82..61d29a2c8 100644
--- a/packages/dashboard-sdk/src/plugin.ts
+++ b/packages/dashboard-sdk/src/plugin.ts
@@ -1,6 +1,7 @@
import type * as Vite from "vite";
import path from "path";
import fs from "fs";
+import { createRequire } from "module";
import { getFileExports } from "./utils";
import {
RESOLVED_ROUTES_MODULE,
@@ -58,6 +59,22 @@ function isMedusaVirtualModule(id: string): boolean {
return MEDUSA_VIRTUAL_MODULES.includes(id);
}
+// Only force-prebundle deps that actually resolve from the app. Consuming apps
+// (e.g. templates) may not declare optional deps like `i18next` or
+// `@medusajs/dashboard` directly, and Vite warns for every unresolved entry in
+// `optimizeDeps.include`.
+function filterResolvableDeps(specifiers: string[], fromDir: string): string[] {
+ const require = createRequire(path.join(fromDir, "noop.js"));
+ return specifiers.filter((specifier) => {
+ try {
+ require.resolve(specifier);
+ return true;
+ } catch {
+ return false;
+ }
+ });
+}
+
function resolveMedusaVirtualModule(id: string): string {
return "\0" + id;
}
@@ -289,18 +306,21 @@ export function mercurDashboardPlugin(pluginConfig: MercurConfig): Vite.Plugin {
"virtual:mercur/custom-fields",
...MEDUSA_VIRTUAL_MODULES,
],
- include: [
- "react",
- "react/jsx-runtime",
- "react-dom/client",
- "react-router-dom",
- "react-i18next",
- "i18next",
- "@medusajs/ui",
- "@medusajs/dashboard",
- "@mercurjs/client",
- "@tanstack/react-query",
- ],
+ include: filterResolvableDeps(
+ [
+ "react",
+ "react/jsx-runtime",
+ "react-dom/client",
+ "react-router-dom",
+ "react-i18next",
+ "i18next",
+ "@medusajs/ui",
+ "@medusajs/dashboard",
+ "@mercurjs/client",
+ "@tanstack/react-query",
+ ],
+ root,
+ ),
},
};
},
diff --git a/packages/vendor/src/pages/price-lists/common/utils.ts b/packages/vendor/src/pages/price-lists/common/utils.ts
index 0a069ceae..2872a3285 100644
--- a/packages/vendor/src/pages/price-lists/common/utils.ts
+++ b/packages/vendor/src/pages/price-lists/common/utils.ts
@@ -1,6 +1,5 @@
import { HttpTypes } from "@medusajs/types"
import i18n, { TFunction } from "i18next"
-import { json } from "react-router-dom"
import { castNumber } from "@lib/cast-number"
import { PriceListDateStatus, PriceListStatus } from "./constants"
import {
@@ -82,7 +81,10 @@ const extractPricesFromVariants = (
: regions.find((r) => r.id === id)?.currency_code
if (!currencyCode) {
- throw json({ message: i18n.t("validation.currencyCodeNotFound") }, 400)
+ throw new Response(
+ JSON.stringify({ message: i18n.t("validation.currencyCodeNotFound") }),
+ { status: 400, headers: { "Content-Type": "application/json" } }
+ )
}
return {
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/areas/index.tsx b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/areas/index.tsx
index 53c311111..adad7d279 100644
--- a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/areas/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/areas/index.tsx
@@ -1,4 +1,4 @@
-import { json, useParams } from "react-router-dom"
+import { useParams } from "react-router-dom"
import { RouteFocusModal } from "@components/modals"
import { useStockLocation } from "@hooks/api/stock-locations"
@@ -18,9 +18,11 @@ const LocationServiceZoneManageAreas = () => {
?.service_zones.find((z) => z.id === zone_id)
if (!isPending && !isFetching && !zone) {
- throw json(
- { message: `Service zone with ID ${zone_id} was not found` },
- 404
+ throw new Response(
+ JSON.stringify({
+ message: `Service zone with ID ${zone_id} was not found`,
+ }),
+ { status: 404, headers: { "Content-Type": "application/json" } }
)
}
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/edit/index.tsx b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/edit/index.tsx
index bee662c15..da8e79875 100644
--- a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/edit/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/edit/index.tsx
@@ -1,6 +1,6 @@
import { Heading } from "@medusajs/ui"
import { useTranslation } from "react-i18next"
-import { json, useParams } from "react-router-dom"
+import { useParams } from "react-router-dom"
import { RouteDrawer } from "@components/modals"
import { useStockLocation } from "@hooks/api/stock-locations"
@@ -20,11 +20,11 @@ const LocationServiceZoneEdit = () => {
?.service_zones.find((z) => z.id === zone_id)
if (!isPending && !isFetching && !serviceZone) {
- throw json(
- {
+ throw new Response(
+ JSON.stringify({
message: `Service zone with ID ${zone_id} was not found`,
- },
- 404
+ }),
+ { status: 404, headers: { "Content-Type": "application/json" } }
)
}
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/edit/index.tsx b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/edit/index.tsx
index 686cc6e0e..ba13d4ccb 100644
--- a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/edit/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/edit/index.tsx
@@ -1,6 +1,6 @@
import { Heading } from "@medusajs/ui"
import { useTranslation } from "react-i18next"
-import { json, useParams } from "react-router-dom"
+import { useParams } from "react-router-dom"
import { RouteDrawer } from "@components/modals"
import { useShippingOptions } from "@hooks/api/shipping-options"
@@ -20,11 +20,11 @@ const LocationServiceZoneShippingOptionEdit = () => {
const shippingOption = shipping_options?.find((so) => so?.id === so_id)
if (!isPending && !isFetching && !shippingOption) {
- throw json(
- {
+ throw new Response(
+ JSON.stringify({
message: `Shipping option with ID ${so_id} was not found`,
- },
- 404
+ }),
+ { status: 404, headers: { "Content-Type": "application/json" } }
)
}
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/pricing/index.tsx b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/pricing/index.tsx
index 0fc2fef9c..5c8417364 100644
--- a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/pricing/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/[so_id]/pricing/index.tsx
@@ -1,5 +1,5 @@
import { useTranslation } from "react-i18next"
-import { json, useParams } from "react-router-dom"
+import { useParams } from "react-router-dom"
import { RouteFocusModal } from "@components/modals"
import { useShippingOption } from "@hooks/api/shipping-options"
@@ -10,10 +10,10 @@ function LocationServiceZoneShippingOptionPricing() {
const { so_id, location_id } = useParams()
if (!so_id) {
- throw json({
- message: t("validation.shippingOptionIdMissing"),
- status: 404,
- })
+ throw new Response(
+ JSON.stringify({ message: t("validation.shippingOptionIdMissing") }),
+ { status: 404, headers: { "Content-Type": "application/json" } }
+ )
}
const {
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/create/index.tsx b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/create/index.tsx
index e40b465d8..cf3afb5d1 100644
--- a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/create/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zone/[zone_id]/shipping-option/create/index.tsx
@@ -1,4 +1,4 @@
-import { json, useParams, useSearchParams } from "react-router-dom"
+import { useParams, useSearchParams } from "react-router-dom"
import { RouteFocusModal } from "@components/modals"
import { useStockLocation } from "@hooks/api/stock-locations"
@@ -21,22 +21,22 @@ function LocationServiceZoneShippingOptionCreate() {
)
if (!isPending && !isFetching && !fulfillmentSet) {
- throw json(
- {
+ throw new Response(
+ JSON.stringify({
message: `Fulfillment set with ID ${fset_id} was not found`,
- },
- 404
+ }),
+ { status: 404, headers: { "Content-Type": "application/json" } }
)
}
const zone = fulfillmentSet?.service_zones?.find((z) => z.id === zone_id)
if (!isPending && !isFetching && !zone) {
- throw json(
- {
+ throw new Response(
+ JSON.stringify({
message: `Service zone with ID ${zone_id} was not found`,
- },
- 404
+ }),
+ { status: 404, headers: { "Content-Type": "application/json" } }
)
}
diff --git a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zones/create/index.tsx b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zones/create/index.tsx
index a1cf146e6..a613c8cee 100644
--- a/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zones/create/index.tsx
+++ b/packages/vendor/src/pages/settings/locations/[location_id]/fulfillment-set/[fset_id]/service-zones/create/index.tsx
@@ -1,4 +1,4 @@
-import { json, useParams } from "react-router-dom"
+import { useParams } from "react-router-dom"
import { RouteFocusModal } from "@components/modals"
import { useStockLocation } from "@hooks/api/stock-locations"
@@ -23,9 +23,11 @@ function LocationCreateServiceZone() {
: FulfillmentSetType.Shipping
if (!isPending && !isFetching && !fulfillmentSet) {
- throw json(
- { message: `Fulfillment set with ID: ${fset_id} was not found.` },
- 404
+ throw new Response(
+ JSON.stringify({
+ message: `Fulfillment set with ID: ${fset_id} was not found.`,
+ }),
+ { status: 404, headers: { "Content-Type": "application/json" } }
)
}
diff --git a/packages/vendor/src/pages/settings/regions/_common/hooks/use-countries.tsx b/packages/vendor/src/pages/settings/regions/_common/hooks/use-countries.tsx
index 34267b893..72c8c5151 100644
--- a/packages/vendor/src/pages/settings/regions/_common/hooks/use-countries.tsx
+++ b/packages/vendor/src/pages/settings/regions/_common/hooks/use-countries.tsx
@@ -1,6 +1,5 @@
import type { StaticCountry } from "@lib/data/countries"
import type { RegionCountryDTO } from "@medusajs/types"
-import { json } from "react-router-dom"
const acceptedOrderKeys = ["name", "code"]
@@ -29,7 +28,10 @@ export const useCountries = ({
if (!acceptedOrderKeys.includes(key)) {
console.log("The key ${key} is not a valid order key")
- throw json(`The key ${key} is not a valid order key`, 500)
+ throw new Response(
+ JSON.stringify(`The key ${key} is not a valid order key`),
+ { status: 500, headers: { "Content-Type": "application/json" } }
+ )
}
const sortKey: keyof RegionCountryDTO = key === "code" ? "iso_2" : "name"
diff --git a/templates/basic/packages/api/src/scripts/seed.ts b/templates/basic/packages/api/src/scripts/seed.ts
index d692ba079..bddd24f12 100644
--- a/templates/basic/packages/api/src/scripts/seed.ts
+++ b/templates/basic/packages/api/src/scripts/seed.ts
@@ -110,6 +110,7 @@ export default async function seedDemoData({ container }: ExecArgs) {
input: {
selector: { id: store.id },
update: {
+ name: 'Mercur Marketplace',
default_sales_channel_id: defaultSalesChannel[0].id,
},
},