Skip to content

Migrate zod v3 to v4#269

Merged
bryantgillespie merged 10 commits into
directus-labs:mainfrom
lilnasy:migrate-zod-3-to-4
Feb 18, 2026
Merged

Migrate zod v3 to v4#269
bryantgillespie merged 10 commits into
directus-labs:mainfrom
lilnasy:migrate-zod-3-to-4

Conversation

@lilnasy

@lilnasy lilnasy commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Before

docker run

   ╭───────────────────────────────────────────────────╮
   │                                                   │
   │                 Update available!                 │
   │                                                   │
   │                 11.10.2 → 11.12.0                 │
   │                 2 versions behind                 │
   │                                                   │
   │                 More information:                 │
   │   https://github.com/directus/directus/releases   │
   │                                                   │
   ╰───────────────────────────────────────────────────╯

file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/core/schemas.js:865
    const first = def.options[0]._zod.run;
                                      ^

TypeError: Cannot read properties of undefined (reading 'run')
    at file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/core/schemas.js:865:39
    at Function.init (file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/core/core.js:14:9)
    at file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/classic/schemas.js:544:20
    at Function.init (file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/core/core.js:14:9)
    at file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/classic/schemas.js:556:14
    at init (file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/core/core.js:14:9)
    at new ZodDiscriminatedUnion (file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/core/core.js:31:9)
    at Module.discriminatedUnion (file:///directus/node_modules/.pnpm/zod@4.0.14/node_modules/zod/v4/classic/schemas.js:561:12)
    at file:///directus/node_modules/.pnpm/@directus+api@file+api_@types+node@24.2.0_typescript@5.8.3/node_modules/@directus/api/dist/websocket/messages.js:4:36
    at ModuleJob.run (node:internal/modules/esm/module_job:343:25)

Node.js v22.18.0

After (see "Loaded extensions")

docker run

   ╭───────────────────────────────────────────────────╮
   │                                                   │
   │                 Update available!                 │
   │                                                   │
   │                 11.10.2 → 11.12.0                 │
   │                 2 versions behind                 │
   │                                                   │
   │                 More information:                 │
   │   https://github.com/directus/directus/releases   │
   │                                                   │
   ╰───────────────────────────────────────────────────╯

[11:25:52.506] INFO: Initializing bootstrap...
[11:25:52.512] INFO: Installing Directus system tables...
[11:25:52.590] INFO: Running migrations...
[91 more lines]
[11:25:54.367] INFO: Setting up first admin role...
[11:25:54.385] INFO: Adding first admin user...
[11:25:54.386] INFO: No admin email provided. Defaulting to "admin@example.com"
[11:25:54.386] INFO: No admin password provided. Defaulting to "15oBBetWMuuJ"
[11:25:54.434] INFO: Done
2025-10-27T11:25:54: PM2 log: Launching in no daemon mode
2025-10-27T11:25:54: PM2 log: App [directus:0] starting in -cluster mode-
   ╭───────────────────────────────────────────────────╮
   │                                                   │
   │                 Update available!                 │
   │                                                   │
   │                 11.10.2 → 11.12.0                 │
   │                 2 versions behind                 │
   │                                                   │
   │                 More information:                 │
   │   https://github.com/directus/directus/releases   │
   │                                                   │
   ╰───────────────────────────────────────────────────╯
2025-10-27T11:25:57: PM2 log: App [directus:0] online
[11:26:01.105] INFO: Extensions loaded
[11:26:01.110] INFO: Loaded extensions: @directus-labs/collaborative-editing, @directus-labs/command-palette-module
[11:26:01.119] WARN: "SECRET" env variable is missing. Using a random value instead. Tokens will not persist between restarts. This is not appropriate for production usage.
[11:26:01.120] WARN: "PUBLIC_URL" should be a full URL
[11:26:01.121] WARN: Spatialite isn't installed. Geometry type support will be limited.
[11:26:01.225] INFO: Server started at http://0.0.0.0:8055

Comment thread packages/collaborative-editing/src/module/utils/errors.ts
Comment thread packages/collaborative-editing/src/module/utils/errors.ts
Comment thread packages/collaborative-editing/src/module/utils/errors.ts
Comment thread packages/collaborative-editing/src/module/settings-fields.ts Outdated
Comment thread packages/collaborative-editing/package.json Outdated
Comment thread packages/command-palette-module/src/types.ts
Comment thread packages/command-palette-module/src/types.ts
Comment thread packages/command-palette-module/package.json Outdated
Comment thread packages/command-palette-module/tsconfig.json
Comment thread packages/command-palette-module/tsconfig.json

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the codebase from Zod v3 to v4 to maintain compatibility with Directus 11.10.2+, which upgraded to Zod v4. The migration addresses breaking API changes in Zod v4's validation schema structure and error handling.

Key Changes:

  • Updated Zod API calls to match v4 syntax (invalid_enum_valueinvalid_value, errorMaperror, etc.)
  • Moved Zod from dependencies to peerDependencies to ensure version compatibility with Directus
  • Updated TypeScript configuration to support Zod v4's module resolution requirements

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/command-palette-module/tsconfig.json Updated lib and moduleResolution for Zod v4 compatibility
packages/command-palette-module/src/utils/errors.ts Migrated error handling from v3 (invalid_enum_value, options) to v4 (invalid_value, values)
packages/command-palette-module/src/types.ts Updated Zod schema syntax: errorMaperror, type casting for nullable/optional, added recentSearchLimit
packages/command-palette-module/package.json Moved zod to peerDependencies, added vue-tsc for type checking
packages/collaborative-editing/src/module/utils/errors.ts Migrated error handling to Zod v4 API
packages/collaborative-editing/src/module/settings-fields.ts Fixed quote escaping in string
packages/collaborative-editing/package.json Moved zod to devDependencies, reordered dependencies alphabetically
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JeremieLeblanc

Copy link
Copy Markdown

Could we take a look at merging this PR?
The CMS starter template breaks because it includes the command palette extension which still uses zod 3.

@bryantgillespie bryantgillespie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine for me locally. Only a few questions on this...

Comment thread packages/collaborative-editing/src/module/utils/errors.ts
Comment thread packages/collaborative-editing/src/module/types.ts
Comment thread packages/command-palette-module/package.json
Comment thread packages/collaborative-editing/package.json
@bryantgillespie bryantgillespie merged commit ac936c5 into directus-labs:main Feb 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants