|
1
|
--- |
|
2
|
sidebar_label: "subscriber-config-export-required" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `subscriber-config-export-required - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires subscriber files to export a `config` object with at least an `event` property. |
|
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's missing the named `config` export, or whose `config` object doesn't declare an `event` property. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/subscribers/order-placed.ts" |
|
24
|
export default async function () {} |
|
25
|
``` |
|
26
|
|
|
27
|
Instead, export a `config` object with an `event` property: |
|
28
|
|
|
29
|
```ts title="src/subscribers/order-placed.ts" |
|
30
|
export default async function () {} |
|
31
|
|
|
32
|
export const config = { |
|
33
|
event: "order.placed", |
|
34
|
} |
|
35
|
``` |
|
36
|
|
|
37
|
## Why it's Important |
|
38
|
|
|
39
|
The `config` export tells Medusa which event(s) the subscriber listens to. Without an `event` property, Medusa can't register the subscriber for any event. |
|
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. |