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)
This commit is contained in:
@@ -128,7 +128,7 @@ import cors from "cors"
|
||||
export const config: MiddlewaresConfig = {
|
||||
routes: [
|
||||
{
|
||||
matcher: "/custom/*",
|
||||
matcher: "/custom*",
|
||||
middlewares: [
|
||||
cors({
|
||||
origin: "*",
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
@@ -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
|
||||
}
|
||||
```
|
||||
@@ -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",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user