#Solving `ReferenceError` in `generate:types` for Lexical Fields

4 messages · Page 1 of 1 (latest)

livid brambleBOT
#

any idea why generate:types keeps giving me this error ReferenceError: Cannot access 'contentField' before initialization?

trying to get standardised lexical field exposed across collections

import type { Field } from 'payload/types'
import {
  BlocksFeature,
  HTMLConverterFeature,
  LexicalBlock,
  lexicalEditor,
  TreeViewFeature,
} from '@payloadcms/richtext-lexical'
import { Archive } from '@/blocks/ArchiveBlock'
import { Content } from '@/blocks/ContentBlock'
import { Hero } from '@/blocks/HeroBlock'
import { Logos } from '@/blocks/LogosBlock'
import { Reuse } from '@/blocks/ReuseBlock'
import type { RichTextField } from 'payload/types'

// Define the ContentField type
type ContentField = (overrides?: Partial<RichTextField>) => RichTextField

// Define the contentField function
export const contentField: ContentField = (overrides) => {
  const fieldOverrides = { ...(overrides || {}) }
  delete fieldOverrides.admin

  return deepMerge<RichTextField, Partial<RichTextField>>(
    {
      name: 'content',
      // label: 'Content',
      type: 'richText',
      required: false,
      editor: lexicalEditor({
        features: ({ defaultFeatures }) => [
          ...defaultFeatures,
          HTMLConverterFeature({}),
          TreeViewFeature(),
          BlocksFeature({
            blocks: [Hero, Logos, Content, Archive, Reuse] as unknown as LexicalBlock[],
          }),
        ],
      }),
    },
    fieldOverrides || {},
  )
}```


and it fails in the attached content block

gahh..ignore me -- just saw the circular relationship with ContentBlock

🤡
eternal rivetBOT
#

Original message from @polar lynx - Moved from #general message

astral perch
#

moved to community help as it could be useful for others if they find this