www/apps/resources/app/lint/rules/zod-import-source/page.mdx
export const metadata = {
title: zod-import-source - ESLint plugin rules,
}
This rule requires importing Zod from @medusajs/framework/zod (Medusa v2.13+), not the bare zod package.
warn. This rule is enabled in the recommended preset.
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:
// non-compliant
import { z } from "zod"
Instead, import from the Medusa Framework entry point:
// compliant
import { z } from "@medusajs/framework/zod"
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.
This rule is auto-fixable. Run the linter with the --fix option to apply the fix automatically.
To turn off this rule, set it to off in your ESLint configuration:
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:
// eslint-disable-next-line @medusajs/zod-import-source
import { z } from "zod"