decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.91k stars 3.04k forks source link

TypeError: Cannot read property 'get' of undefined #4480

Open lukeocodes opened 4 years ago

lukeocodes commented 4 years ago

Describe the bug

I have enabled i18n for content authoring. I believe I should be able to save a post in the primary language without adding all the translations at the same time. When I try to save, I get no visible error. Instead, I get this error in the console.

To Reproduce

  1. On a site configured as my config linked below
  2. Go to /admin
  3. Click on 'New Blog Post'
  4. Complete the form for the English post
  5. Try and click on 'Save'
  6. See error in console

Expected behavior

  1. On a site configured as my config linked below
  2. Go to /admin
  3. Click on 'New Blog Post'
  4. Complete the form for the English post
  5. Try and click on 'Save'
  6. Saves only the translation you've created

Screenshots

TypeError: Cannot read property 'get' of undefined

Entire console output including TypeError

Applicable Versions:

CMS configuration

https://github.com/Nexmo/deved-platform/blob/i18n-netlify-cms/static/admin/config.yml

Additional context

If I complete all the fields for all the languages, it then lets me save!

lukeocodes commented 4 years ago

This error occurred in these other issues (#4327 #3772 #3690) but based on the config and the lack of errors I couldn't be sure if related. They're all closed without resolution too.

frankspin89 commented 4 years ago

Yes, this error seems to be related only to creating new content without entering all translations.

Versions:

app.js

// This global flag enables manual initialization.
window.CMS_MANUAL_INIT = true

import CMS from 'netlify-cms-app'

import { pages } from './collections/pages'

CMS.init({
  config: {
    load_config_file: false,
    local_backend: true,
    media_folder: '/static/meda',
    public_folder: '/meda',
    backend: {
      name: 'git-gateway'
    },
    media_library: {
      name: '',
      config: {
        max_file_size: 700000
      }
    },
    i18n: {
      structure: 'multiple_files',
      locales: ['nl', 'en', 'de'],
      default_locale: 'nl'
    },
    collections: [pages]
  },
})

Pages collection

import { image } from "../partials/image"

const fields = [
  {
    label: 'Title',
    name: 'title',
    widget: 'string',
    required: false,
    i18n: true
  },
  {
    label: 'Url',
    name: 'url',
    widget: 'string',
    required: false,
    i18n: true
  },
  image
]

const pages = {
  label: 'Pages',
  name: 'pages',
  create: true,
  i18n: true,
  media_folder: 'images',
  public_folder: 'images',
  format: 'frontmatter',
  path: '{{slug}}/index',
  editor: {
    preview: false
  },
  folder: 'content/pages',
  fields: [
    ...fields
  ],
}

export {
  pages
}

Image

  label: "Image",
  name: 'image',
  widget: 'object',
  i18n: true,
  fields: [
    {
      label: 'Source',
      name: 'source',
      widget: 'image',
      required: false,
      i18n: true
    },
    {
      label: 'Alt text',
      name: 'alt',
      widget: 'string',
      required: false,
      i18n: true
    },
  ]
}

Error on creating page

netlify-cms-app.js:167 Uncaught (in promise) TypeError: Cannot read property 'get' of undefined
    at eval (netlify-cms-app.js:167)
    at eval (netlify-cms-app.js:1)
    at it.__iterate (netlify-cms-app.js:1)
    at it.reduce (netlify-cms-app.js:1)
    at s (netlify-cms-app.js:167)
    at t.serializeValues (netlify-cms-app.js:167)
    at r (netlify-cms-app.js:34)
    at eval (netlify-cms-app.js:43)
    at Array.forEach (<anonymous>)
    at t.serializeI18n (netlify-cms-app.js:43)
lukeocodes commented 4 years ago

Let me know if you need anything else, happy to help :)

sammy42 commented 3 years ago

Hi @lukeocodes, did you manage to solve this issue or find a workaround ? I cannot save any records and setting fields as required: false, default: "" doesn't help.

lukeocodes commented 3 years ago

Seemed to me to be a limitation of i18n, to assume there is always a translation

sammy42 commented 3 years ago

It's a big limitation in some situations, limitation which isn't written anywhere in the doc, and presents itself as a bug to the users. Basically with i18n all the fields become mandatory and for every language. With a dozen languages to translate and many keys in each document there is no way to save a draft after editing a subset of them. It feels like it's the required: false option that doesn't work. This bug appears even when all the fields are optional.