nicoespeon/zod-v3-to-v4(新しいタブで開きます)
主要言語: TypeScript
A codemod to migrate from Zod v3 to v4
- star 数
- 114
- watcher 数
- 2
- fork 数
- 8
- issue 数
- 0
- 最終更新
- 2026/10/29
主要言語: TypeScript
A codemod to migrate from Zod v3 to v4
This is a codemod (a tool that automatically transforms code) for migrating from Zod v3 to v4.
The migration guide can be found at https://zod.dev/v4/changelog
This assumes you have Node.js installed.
The first step for you is to upgrade your Zod version to v4. In doubt, check your package.json. Note that if you're using Zod through Astro v6, you don't need to upgrade Zod manually.
Then, you can use this codemod to automatically migrate your code from Zod v3 to v4 syntax.
This codemod also migrates .vue files containing Zod schemas.
You can run it with the following command:
npx zod-v3-to-v4
It will ask you for the path to your tsconfig.json file, and then it will go through all your files and migrate Zod v3 code to v4.
Alternatively, you can pass the path to your tsconfig.json file as an argument:
npx zod-v3-to-v4 path/to/your/tsconfig.json
You can also pass -y (or --yes) to automatically answer "yes" to confirmation prompts (such as migrating all referenced packages in a monorepo):
npx zod-v3-to-v4 path/to/your/tsconfig.json -y
Without a path, -y uses the tsconfig.json of the current directory. With -y, an invalid path fails with an error instead of prompting.
This is useful if you ever need to run the codemod in script (e.g. in a CI pipeline).
You can also install it as a package and run it from your project:
npm install -ED zod-v3-to-v4
And then run it with:
npx zod-v3-to-v4
If the codemod missed something or did something wrong, please open an issue.
This project uses node.js and pnpm. To get started, run:
pnpm install
To run the tests, run:
pnpm testWe use ts-morph to parse and transform the code.
Useful links:
If you want to test the codemod from CLI, you can use the playground folder. It contains a tsconfig.json file and some sample TypeScript files with Zod v3 code. You can run the codemod on these files with:
pnpm playground
Or interactively:
pnpm playground:interactive
# Then enter: playground/tsconfig.json