|
1
|
--- |
|
2
|
sidebar_label: "import-from-framework-not-internal" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `import-from-framework-not-internal - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires using the public `@medusajs/framework/*` entry points, and disallows importing from a package's internal `dist/` build output or from deprecated standalone packages. |
|
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 deprecated standalone packages, such as `@medusajs/utils`, and from internal `dist/` build output, such as `@medusajs/medusa/dist/...`. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/api/example.ts" |
|
24
|
// non-compliant |
|
25
|
import { MedusaError } from "@medusajs/utils" |
|
26
|
``` |
|
27
|
|
|
28
|
Instead, import from the Medusa Framework entry point: |
|
29
|
|
|
30
|
```ts title="src/api/example.ts" |
|
31
|
// compliant |
|
32
|
import { MedusaError } from "@medusajs/framework/utils" |
|
33
|
``` |
|
34
|
|
|
35
|
## Why it's Important |
|
36
|
|
|
37
|
The `@medusajs/framework/*` entry points are the supported public surface. Deprecated packages and internal build paths can change or disappear between versions, breaking your project. |
|
38
|
|
|
39
|
## Fixable |
|
40
|
|
|
41
|
This rule is auto-fixable for some paths. For example, the rule can fix an import of `@medusajs/utils` to `@medusajs/framework/utils`. 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/import-from-framework-not-internal": "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/import-from-framework-not-internal |
|
65
|
import { MedusaError } from "@medusajs/utils" |
|
66
|
``` |