Back to Medusa

{metadata.title}

www/apps/resources/app/lint/rules/zod-import-source/page.mdx

2.17.01.6 KB
Original Source

export const metadata = { title: zod-import-source - ESLint plugin rules, }

{metadata.title}

This rule requires importing Zod from @medusajs/framework/zod (Medusa v2.13+), not the bare zod package.

Severity

warn. This rule is enabled in the recommended preset.

What it Targets

This rule targets all files in your backend customizations. It reports imports and re-exports whose source is the bare zod package.

The following code is reported by the rule:

ts
// non-compliant
import { z } from "zod"

Instead, import from the Medusa Framework entry point:

ts
// compliant
import { z } from "@medusajs/framework/zod"

Why it's Important

Importing Zod from @medusajs/framework/zod ensures you use the same Zod version Medusa relies on, avoiding version mismatches and duplicate copies in your project.

Learn more in the API route validation documentation.

Fixable

This rule is auto-fixable. Run the linter with the --fix option to apply the fix automatically.

Turn it Off

To turn off this rule, set it to off in your ESLint configuration:

ts
import { defineConfig } from "eslint/config"
import medusa from "@medusajs/eslint-plugin"

export default defineConfig([
  ...medusa.configs.recommended,
  {
    rules: {
      "@medusajs/zod-import-source": "off",
    },
  },
])

Or disable it for a single line using an inline comment:

ts
// eslint-disable-next-line @medusajs/zod-import-source
import { z } from "zod"