|
1
|
--- |
|
2
|
sidebar_label: "admin-no-medusa-utils-import" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `admin-no-medusa-utils-import - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule disallows importing Node-only modules from the Medusa Framework (`@medusajs/framework/utils`, `@medusajs/framework/http`, and `@medusajs/framework/workflows-sdk`) in admin code, since they break the browser bundle. |
|
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/admin` directory. It reports an import or re-export of a Node-only module from the Medusa Framework. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```tsx title="src/admin/widgets/product-widget.tsx" |
|
24
|
import { MedusaError } from "@medusajs/framework/utils" |
|
25
|
``` |
|
26
|
|
|
27
|
Instead, move the logic to the server and call it from the admin via the JS SDK: |
|
28
|
|
|
29
|
```tsx title="src/admin/widgets/product-widget.tsx" |
|
30
|
import { sdk } from "../lib/sdk" |
|
31
|
``` |
|
32
|
|
|
33
|
## Why it's Important |
|
34
|
|
|
35
|
The admin dashboard is a browser bundle. Importing Node-only modules breaks the admin build or ships server-only code to the client. |
|
36
|
|
|
37
|
Learn more in the [Admin Development documentation](!docs!/learn/fundamentals/admin). |
|
38
|
|
|
39
|
## Fixable |
|
40
|
|
|
41
|
This rule isn't auto-fixable. |