10.3.2. Replace Zod Imports Codemod (v2.13.0+)

In this chapter, you'll learn about the codemod that helps you replace Zod imports in your codebase when upgrading to Medusa v2.13.0.

What is the Replace Zod Imports Codemod?#

As of v2.13.0, Medusa exports Zod from the @medusajs/framework package.

Zod is a validation library that you can use to validate request bodies, query parameters, and more in your Medusa application.

Starting in v2.13.0, you can import Zod from @medusajs/framework/zod in your backend customizations. For example:

Code
import { z } from "@medusajs/framework/zod"

For Medusa Admin customizations, you can install and import Zod as needed.

The replace-zod-imports codemod automates the process of updating your import statements to use the new Zod import path. Use it after updating your Medusa project to v2.13.0 or later.


How to Run the Codemod#

To use the replace imports codemod, update your Medusa project to v2.13.0 or later. Refer to the Update Medusa guide for instructions.

Then, run the following command in the root directory of your Medusa project:

This command scans your codebase for Zod import statements in the backend customizations and replaces them with the new import path.

All Zod imports will be changed to:

Code
import { z } from "@medusajs/framework/zod"

Next Steps#

After running the codemod, review the changes made to your codebase. You can:

  • Use git diff to see the modifications.
  • Run your tests to ensure everything works as expected.

If everything is working correctly, you can push the changes to your repository. If you've installed zod and you're not using it for Medusa Admin customizations, you can remove it from your package.json dependencies.

Was this chapter helpful?
Ask Anything
For assistance in your development, use Claude Code Plugins or Medusa MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break