From d1f697c88e20e82ff0423e8a9d0bd86c6b0730e4 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 13 Feb 2024 13:32:02 +0200 Subject: [PATCH] docs: new troubleshooting guide + cors fix (#6387) - Fixed CORS middleware to account for routes of a single path (for example, `/custom` and not just `/custom/test`). - Added a troubleshooting guide for admin webpack errors (see issue #6375) --- .../content/development/api-routes/create.mdx | 2 +- .../plugins/notifications/sendgrid.mdx | 2 +- .../admin-webpack-build-types.md | 91 +++++++++++++++++++ www/apps/docs/sidebars.js | 5 + 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 www/apps/docs/content/troubleshooting/admin-webpack-build-types.md diff --git a/www/apps/docs/content/development/api-routes/create.mdx b/www/apps/docs/content/development/api-routes/create.mdx index 16876540c5..fb063f90e3 100644 --- a/www/apps/docs/content/development/api-routes/create.mdx +++ b/www/apps/docs/content/development/api-routes/create.mdx @@ -128,7 +128,7 @@ import cors from "cors" export const config: MiddlewaresConfig = { routes: [ { - matcher: "/custom/*", + matcher: "/custom*", middlewares: [ cors({ origin: "*", diff --git a/www/apps/docs/content/plugins/notifications/sendgrid.mdx b/www/apps/docs/content/plugins/notifications/sendgrid.mdx index b9a3e76728..ecfab0e1b6 100644 --- a/www/apps/docs/content/plugins/notifications/sendgrid.mdx +++ b/www/apps/docs/content/plugins/notifications/sendgrid.mdx @@ -145,7 +145,7 @@ const plugins = [ product_created_template: process.env.SENDGRID_ORDER_CREATED_ID, my_custom_event_template: - process.env.SENDGRID_CUSTOM_EVENT_ID + process.env.SENDGRID_CUSTOM_EVENT_ID, }, }, ] diff --git a/www/apps/docs/content/troubleshooting/admin-webpack-build-types.md b/www/apps/docs/content/troubleshooting/admin-webpack-build-types.md new file mode 100644 index 0000000000..829197156c --- /dev/null +++ b/www/apps/docs/content/troubleshooting/admin-webpack-build-types.md @@ -0,0 +1,91 @@ +--- +title: Admin Webpack Build Error +--- + +If you run the `build` command in your backend and you get an error message during the admin build process similar to the following: + +```bash +The left-hand side of an assignment expression must be a variable or a property access. +``` + +Make sure that in your admin customizations (widget, UI route, or settings page) you're not using a type imported from `@medusajs/medusa`. + +This is often the case if you're using a type or an enum necessary for a request sent with the JS Client or Medusa React library. + +For example: + +```ts +import { + Region, + ShippingOptionPriceType, +} from "@medusajs/medusa" +import type Medusa from "@medusajs/medusa-js" + +export default async function prepareShippingOptions( + client: Medusa, + region: Region +) { + let { + shipping_options, + } = await client.admin.shippingOptions.list({ + region_id: region.id, + }) + if (!shipping_options.length) { + shipping_options = [( + await client.admin.shippingOptions.create({ + "name": "PostFake Standard", + "region_id": region.id, + "provider_id": "manual", + "data": { + "id": "manual-fulfillment", + }, + // THIS CAUSES THE ERROR + "price_type": ShippingOptionPriceType.FLAT_RATE, + "amount": 1000, + } + )).shipping_option] + } + + return shipping_options +} +``` + +In this case, you're using the `ShippingOptionPriceType` type to send a request with the JS Client. + +Instead, change it to the string value. If you get a TypeScript error, you can add `// @ts-ignore` before the line: + +```ts +import { + Region, + ShippingOptionPriceType, +} from "@medusajs/medusa" +import type Medusa from "@medusajs/medusa-js" + +export default async function prepareShippingOptions( + client: Medusa, + region: Region +) { + let { + shipping_options, + } = await client.admin.shippingOptions.list({ + region_id: region.id, + }) + if (!shipping_options.length) { + shipping_options = [( + await client.admin.shippingOptions.create({ + "name": "PostFake Standard", + "region_id": region.id, + "provider_id": "manual", + "data": { + "id": "manual-fulfillment", + }, + // @ts-expect-error can't use type from core + "price_type": "flat_rate", + "amount": 1000, + } + )).shipping_option] + } + + return shipping_options +} +``` diff --git a/www/apps/docs/sidebars.js b/www/apps/docs/sidebars.js index c1a01f4837..84a5496f8e 100644 --- a/www/apps/docs/sidebars.js +++ b/www/apps/docs/sidebars.js @@ -2244,6 +2244,11 @@ module.exports = { id: "troubleshooting/custom-hooks-error", label: "Custom Hooks Error", }, + { + type: "doc", + id: "troubleshooting/admin-webpack-build-types", + label: "Webpack Build Error", + }, ], }, {