Back to Medusa

{metadata.title}

www/apps/resources/app/lint/rules/subscriber-default-export-required/page.mdx

2.17.01.1 KB
Original Source

export const metadata = { title: subscriber-default-export-required - ESLint plugin rules, }

{metadata.title}

This rule requires subscriber files to default-export the subscriber function.

Severity

error. This rule is enabled in the recommended preset.

What it Targets

This rule targets files in your project's src/subscribers directory. It reports a subscriber file that has no default export.

The following code is reported by the rule:

ts
export const orderPlacedHandler = async () => {}

Instead, default-export the subscriber handler function:

ts
export default async function orderPlacedHandler() {}

export const config = {
  event: "order.placed",
}

Why it's Important

Medusa registers and runs the subscriber's default export when its event is emitted. Without a default export, the subscriber never runs.

Learn more in the Subscribers documentation.

Fixable

This rule isn't auto-fixable.