payloadcms / payloadcms/payload

generate:types crashes on object-form localization.locales (json-schema-to-typescript TypeError: endsWith of undefined)

Open
#17,858 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
44.8k
Forks
4.2k
Avg merge
2d 21h
Merged PRs (30d)
53

Description

Describe the Bug

payload generate:types crashes with a TypeError inside json-schema-to-typescript when config-level localization.locales uses the object form ({ label, value }) and at least one collection has a localized field. The documented string-array form works fine in the identical config.

Link to the Code that Reproduces this Issue

Minimal config that crashes:

import { buildConfig } from "payload";

export default buildConfig({
  localization: {
    locales: [
      { label: "English", value: "en" },
      { label: "French", value: "fr" },
    ],
    defaultLocale: "en",
    fallback: true,
  },
  collections: [
    {
      slug: "posts",
      fields: [{ name: "title", type: "text", localized: true }],
    },
  ],
});

Swapping locales to ["en", "fr"] makes generate:types succeed — everything else unchanged.

Reproduction Steps

  1. pnpm dlx create-payload-app@latest (or any Payload 3.88.0 project).
  2. Set localization.locales to the object form above and add one localized field.
  3. Run pnpm payload generate:types.

Expected / Actual Behaviors

Expected: types are generated for either documented locale form.
Actual: with the object form:

Error generating types: TypeError: Cannot read properties of undefined (reading 'endsWith')
    ... json-schema-to-typescript ...

Environment Info

Output of npx payload info:

Binaries:
  Node: 22.22.2
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.x
Relevant Packages:
  payload: 3.88.0
  next: 16.3.1
  @payloadcms/ui: 3.88.0
  react: 19.x
  typescript: 5.7.3
  json-schema-to-typescript: 15.0.3 (payload dependency)
Operating System: macOS 15.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the documented object-form localization.locales and a localized field, then trace the generate:types entry point into its localized-field schema generation. Check how json-schema-to-typescript receives the locale data. Done means generation succeeds for both the object and string-array locale forms, with the existing configuration unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.