Back to Medusa

{metadata.title}

www/apps/resources/app/lint/rules/widget-must-have-default-export/page.mdx

2.17.01.3 KB
Original Source

export const metadata = { title: widget-must-have-default-export - ESLint plugin rules, }

{metadata.title}

This rule requires widget files to default-export the widget component.

Severity

error. This rule is enabled in the recommended preset.

What it Targets

This rule targets files in your project's src/admin/widgets directory. It reports a widget file that doesn't have a default export.

The following code is reported by the rule:

tsx
import { defineWidgetConfig } from "@medusajs/admin-sdk"

const MyWidget = () => null

export const config = defineWidgetConfig({
  zone: "product.details.before",
})

export { MyWidget }

Instead, default-export the widget component:

tsx
import { defineWidgetConfig } from "@medusajs/admin-sdk"

const MyWidget = () => null

export const config = defineWidgetConfig({
  zone: "product.details.before",
})

export default MyWidget

Why it's Important

Medusa renders the default export of a widget file in the configured zones. Without a default export, the widget has no component to render.

Learn more in the Admin Widgets documentation.

Fixable

This rule isn't auto-fixable.