Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lukeocodes opened this issue Oct 19, 2020 · 6 comments
Open

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

lukeocodes opened this issue Oct 19, 2020 · 6 comments
Labels
area: i18n type: bug code to address defects in shipped code

Comments

@lukeocodes
Copy link

lukeocodes commented Oct 19, 2020

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:

  • Netlify CMS: 2.10.63
  • Git provider: GitHub
  • OS: Mac
  • Browser version: Version 86.0.4240.80 (Official Build) (x86_64)

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 lukeocodes added the type: bug code to address defects in shipped code label Oct 19, 2020
@lukeocodes
Copy link
Author

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
Copy link

frankspin89 commented Oct 20, 2020

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

Versions:

  • "netlify-cms-app": "^2.12.27",
  • git-gateway, local_backend
  • OS: Windows 10
  • Browser version: Edge Version 86.0.622.43 (Official build) (64-bit)

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
Copy link
Author

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

@sammy42
Copy link

sammy42 commented Oct 20, 2021

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
Copy link
Author

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

@sammy42
Copy link

sammy42 commented Oct 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: i18n type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

4 participants