|
1
|
--- |
|
2
|
sidebar_label: "no-mikroorm-direct-import" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `no-mikroorm-direct-import - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule disallows importing MikroORM or awilix directly. As of Medusa v2.11, they're bundled into `@medusajs/framework`, so use the `@medusajs/framework/mikro-orm/*` and `@medusajs/framework/awilix` re-exports. |
|
12
|
|
|
13
|
## Severity |
|
14
|
|
|
15
|
`warn`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset. |
|
16
|
|
|
17
|
## What it Targets |
|
18
|
|
|
19
|
This rule targets all files in your project. It reports imports and re-exports from `@mikro-orm/*` packages or the bare `awilix` package. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/modules/example.ts" |
|
24
|
// non-compliant |
|
25
|
import { EntityManager } from "@mikro-orm/core" |
|
26
|
``` |
|
27
|
|
|
28
|
Instead, import from the Medusa Framework re-export: |
|
29
|
|
|
30
|
```ts title="src/modules/example.ts" |
|
31
|
// compliant |
|
32
|
import { EntityManager } from "@medusajs/framework/mikro-orm/core" |
|
33
|
``` |
|
34
|
|
|
35
|
## Why it's Important |
|
36
|
|
|
37
|
Using the Medusa Framework re-exports ensures you depend on the same MikroORM and awilix versions Medusa uses, avoiding version mismatches and duplicate copies in your project. |
|
38
|
|
|
39
|
## Fixable |
|
40
|
|
|
41
|
This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically. |
|
42
|
|
|
43
|
## Turn it Off |
|
44
|
|
|
45
|
To turn off this rule, set it to `off` in your ESLint configuration: |
|
46
|
|
|
47
|
```ts title="eslint.config.ts" |
|
48
|
import { defineConfig } from "eslint/config" |
|
49
|
import medusa from "@medusajs/eslint-plugin" |
|
50
|
|
|
51
|
export default defineConfig([ |
|
52
|
...medusa.configs.recommended, |
|
53
|
{ |
|
54
|
rules: { |
|
55
|
"@medusajs/no-mikroorm-direct-import": "off", |
|
56
|
}, |
|
57
|
}, |
|
58
|
]) |
|
59
|
``` |
|
60
|
|
|
61
|
Or disable it for a single line using an inline comment: |
|
62
|
|
|
63
|
```ts |
|
64
|
// eslint-disable-next-line @medusajs/no-mikroorm-direct-import |
|
65
|
import { EntityManager } from "@mikro-orm/core" |
|
66
|
``` |