Creating a block definition to replace previous block causes error

default discord avatar
thisisnotchris
6 months ago
42

"index.js:179 Uncaught TypeError: Cannot destructure property 'blockType' of 'row' as it is undefined."



@jmikrut Sorry for ping, but I'm worried I broke something...is it possible my payload install is behind?



This is on the admin side, adding a Block to a collection



The page goes blank and prints that error



I'm on

"payload": "^1.3.0"


import { Block, CollectionConfig } from "payload/types";

const BannerBlock: Block = {
  slug: "Banner",
  fields: [
    {
      name: "section",
      type: "text",
      required: true,
    },
    {
      name: "title",
      label: "Image Banner Title",
      type: "text",
      required: true,
    },
    {
      name: "subtitle",
      label: "Image Banner Sub-Title",
      type: "text",
      required: true,
    },
    {
      name: "image",
      type: "upload",
      relationTo: "media",
      required: true,
    },
  ],
};

const PanelBlock: Block = {
  slug: "Panels",
  fields: [
    {
      name: "section",
      type: "text",
      required: true,
    },
    {
      name: "panels", // required
      type: "array", // required
      label: "Content Panels",
      minRows: 1,
      maxRows: 4,
      labels: {
        singular: "Panel",
        plural: "Panels",
      },
      fields: [
        {
          name: "title",
          type: "text",
          required: true,
        },
        {
          name: "content",
          type: "textarea",
        },
        {
          name: "link",
          type: "text",
        },
        {
          name: "icon",
          type: "text",
        },
      ],
    },
  ],
};

const Pages: CollectionConfig = {
  slug: "pages",
  access: {
    read: () => true,
  },
  admin: {
    useAsTitle: "title",
  },
  fields: [
    {
      name: "title",
      label: "Page Title",
      type: "text",
      required: true,
      unique: true,
    },
    {
      name: "description",
      label: "Page Description",
      type: "textarea",
      required: true,
    },
    {
      name: "layout", // required
      type: "blocks", // required
      minRows: 1,
      maxRows: 20,
      blocks: [BannerBlock, PanelBlock],
    },
  ],
};

export default Pages;
  • discord user avatar
    jmikrut
    Payload Team
    6 months ago

    what is the Payload version that you actually have installed?



    i would also try and use these exact field configs in a brand-new and empty Payload project created with

    npx create-payload-app

    , to see if the problem persists



    this seems like a data problem, maybe you have docs that are out of date or similar. but if you can create this issue with a new / blank project, using these exact field / block definitions, then it would appear to be a bug and we can help look at this immediately

  • default discord avatar
    thisisnotchris
    6 months ago

    @jmikrut Thanks my friend!



    @jmikrut Sadly updating did not fix the issue :/



    I had a block before, "SliderBlock"



    I renamed it, changed its schema a bit



    To BannerBlock



    updated the collection config



    But now I can add blocks to the collection



    cant*

  • discord user avatar
    jmikrut
    Payload Team
    6 months ago

    ahhh ok, if you renamed it, you should write a migration script to go through all your old docs, find any instances of the old block slug, and update them to the new block slug

  • default discord avatar
    thisisnotchris
    6 months ago

    I'm not sure how to do that



    I figured it would take care of that kind of thing for me :X

  • discord user avatar
    jmikrut
    Payload Team
    6 months ago

    i believe there are some examples in our GitHub discussions about quick migration scripts



    but yeah, migrations are manual as with most every ORM. We don't change your existing data ever for you, at least not yet

  • default discord avatar
    thisisnotchris
    6 months ago

    With prisma i can just do like prisma migrate dev --name



    it would be nice to do prisma migrate



    err payload migrate



    and have it do that kind of thing

  • discord user avatar
    jmikrut
    Payload Team
    6 months ago

    that could very well be a thing that we build in the future

  • default discord avatar
    thisisnotchris
    6 months ago

    when i get financially stable enough ill quit my job and join payload



    😛

  • discord user avatar
    jmikrut
    Payload Team
    6 months ago

    well, the good news there is that we will be prioritizing hiring future engineers straight from our community 😈

  • default discord avatar
    thisisnotchris
    6 months ago

    hehe amazing



    My speciality is more like webgl / 3d stuff



    But I do enjoy this kind of dev



    TBH, I was looking at some other headless cms systems last night



    And it's really rough out there



    Payload is the only one who's marketing doesnt automatically make me feel like they just want all my $$$$$



    And ive tried like, 7 of them



    That and it works nicely



    I mean not that you guys dont wnat $ but



    you care about the community



    etc



    anyway, ill let you get back to it



    TY 😄

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.