Back to Medusa

{metadata.title}

www/apps/resources/app/lint/rules/admin-no-medusa-utils-import/page.mdx

2.17.01.2 KB
Original Source

export const metadata = { title: admin-no-medusa-utils-import - ESLint plugin rules, }

{metadata.title}

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.

Severity

error. This rule is enabled in the recommended preset.

What it Targets

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.

The following code is reported by the rule:

tsx
import { MedusaError } from "@medusajs/framework/utils"

Instead, move the logic to the server and call it from the admin via the JS SDK:

tsx
import { sdk } from "../lib/sdk"

Why it's Important

The admin dashboard is a browser bundle. Importing Node-only modules breaks the admin build or ships server-only code to the client.

Learn more in the Admin Development documentation.

Fixable

This rule isn't auto-fixable.