Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

TypeError: (0 , link_1.default) is not a function

default discord avatar
taun2160last year
2
F:\git\Melex_2\payload\src\fields\richText\index.ts:38
                link({
                    ^
TypeError: (0 , link_1.default) is not a function


Any ideas?



Also, I'm setting up a boilerplate template to service clients and give them the option to add their own pages, with Blocks layouts. I assume this RichText component is fundamental to a good content editing experience and this template I'm aiming to create?



import type { RichTextElement, RichTextField, RichTextLeaf } from 'payload/dist/fields/config/types'

import deepMerge from '../../utilities/deepMerge'
import link from '../link'
import elements from './elements'
import leaves from './leaves'

type RichText = (
  overrides?: Partial<RichTextField>,
  additions?: {
    elements?: RichTextElement[]
    leaves?: RichTextLeaf[]
  },
) => RichTextField

const richText: RichText = (
  overrides,
  additions = {
    elements: [],
    leaves: [],
  },
) =>
  deepMerge<RichTextField, Partial<RichTextField>>(
    {
      name: 'richText',
      type: 'richText',
      required: true,
      admin: {
        upload: {
          collections: {
            media: {
              fields: [
                {
                  name: 'enableLink',
                  type: 'checkbox',
                  label: 'Enable Link',
                },
                link({
                  appearances: false,
                  disableLabel: true,
                  overrides: {
                    admin: {
                      condition: (_, data) => Boolean(data?.enableLink),
                    },
                  },
                }),
              ],
            },
          },
        },
        elements: [...elements, ...(additions.elements || [])],
        leaves: [...leaves, ...(additions.leaves || [])],
      },
    },
    overrides,
  )

export default richText


Within link.ts, I'm receiving an error regarding the PageType - does this correlate to the OP error? How might I solve?



  • default discord avatar
    jessrynkarlast year

    Hi

    @479030528084017165

    - looks like you need to import

    PageType

    . Likely needs to be imported from your

    payload-types.ts

    In your

    link.ts

    file can you show me where

    link

    is getting exported?

  • default discord avatar
    taun2160last year

    Thanks

    @854377910689202256

    .



    Here's link.ts


    import { Field } from 'payload/types';
    import { PageType } from 'payload/types';
    
    export type Type = {
      type: 'page' | 'custom'
      label: string
      page?: PageType
      url?: string
    }
    
    const link: Field = {
      name: 'link',
      type: 'group',
      fields: [
        {
          name: 'type',
          type: 'radio',
          options: [
            {
              label: 'Page',
              value: 'page',
            },
            {
              label: 'Custom URL',
              value: 'custom',
            },
          ],
          defaultValue: 'page',
          admin: {
            layout: 'horizontal',
          },
        },
        {
          type: 'row',
          fields: [
            {
              name: 'label',
              label: 'Label',
              type: 'text',
              required: true,
              admin: {
                width: '50%',
              },
            },
            {
              name: 'page',
              label: 'Page to link to',
              type: 'relationship',
              relationTo: 'pages',
              required: true,
              admin: {
                condition: (_, siblingData) => siblingData?.type === 'page',
                width: '50%',
              },
            },
            {
              name: 'url',
              label: 'Custom URL',
              type: 'text',
              required: true,
              admin: {
                condition: (_, siblingData) => siblingData?.type === 'custom',
                width: '50%',
              },
            },
          ],
        },
      ],
    };
    
    export default link;


    PageType doesn't exist in payload-types and I can't access payload-type from the payload-main repo. Do you know what PageType should be defined as?

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.