|
1
|
--- |
|
2
|
sidebar_label: "subscriber-default-export-required" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `subscriber-default-export-required - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires subscriber files to default-export the subscriber function. |
|
12
|
|
|
13
|
## Severity |
|
14
|
|
|
15
|
`error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset. |
|
16
|
|
|
17
|
## What it Targets |
|
18
|
|
|
19
|
This rule targets files in your project's `src/subscribers` directory. It reports a subscriber file that has no default export. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/subscribers/order-placed.ts" |
|
24
|
export const orderPlacedHandler = async () => {} |
|
25
|
``` |
|
26
|
|
|
27
|
Instead, default-export the subscriber handler function: |
|
28
|
|
|
29
|
```ts title="src/subscribers/order-placed.ts" |
|
30
|
export default async function orderPlacedHandler() {} |
|
31
|
|
|
32
|
export const config = { |
|
33
|
event: "order.placed", |
|
34
|
} |
|
35
|
``` |
|
36
|
|
|
37
|
## Why it's Important |
|
38
|
|
|
39
|
Medusa registers and runs the subscriber's default export when its event is emitted. Without a default export, the subscriber never runs. |
|
40
|
|
|
41
|
Learn more in the [Subscribers documentation](!docs!/learn/fundamentals/events-and-subscribers). |
|
42
|
|
|
43
|
## Fixable |
|
44
|
|
|
45
|
This rule isn't auto-fixable. |