payload icon indicating copy to clipboard operation
payload copied to clipboard

Import Admin Components Error with 3.0.0-beta.81

Open mednet-ecrep opened this issue 2 years ago • 6 comments

Link to reproduction

No response

Payload Version

3.0.0-beta.81

Node Version

v20.9.0

Next.js Version

15.0.0-canary.104

Describe the Bug

I'm not sure if it's really a bug or if I implemented the graphics incorrectly. I've tried two different approaches, and both resulted in an error. When I remove the admin graphics from the config, everything works fine.

First test:

admin: {
    user: 'admins',
    meta: {
      titleSuffix: '- mydomain',
    },
    components: {
      graphics: {
        Icon: { path: '/src/payload/graphics/index.tsx', exportName: 'Icon' },
        Logo: { path: '/src/payload/graphics/index.tsx', exportName: 'Logo' },
      },
    },

Error:

Module not found: Can't resolve 'srcpayloadgraphicsindex.tsx'
import { Icon as Icon_27 } from '\src\payload\graphics\index.tsx'
https://nextjs.org/docs/messages/module-not-found

Second test:

  admin: {
    user: 'admins',
    meta: {
      titleSuffix: '- mydomain.com',
    },
    components: {
      graphics: {
        Logo: {
          path: './src/payload/graphics/index.tsx#Logo',
        },
        Icon: {
          path: './src/payload/graphics/index.tsx#Icon',
        },
      },
    },

Error:

 ⨯ ./src/app/(payload)/admin/importMap.js:28:1
Module not found: Can't resolve 'srcpayloadgraphicsindex.tsx'
  26 | import { MetaDescriptionComponent as MetaDescriptionComponent_25 } from '@payloadcms/plugin-seo/client'
  27 | import { PreviewComponent as PreviewComponent_26 } from '@payloadcms/plugin-seo/client'
> 28 | import { Icon as Icon_27 } from 'src\payload\graphics\index.tsx'
     | ^
  29 | import { Logo as Logo_28 } from 'src\payload\graphics\index.tsx'
  30 |
  31 | export const importMap = {


https://nextjs.org/docs/messages/module-not-found

This is the file (/src/payload/graphics/index.tsx:

import React from 'react'
import Image from 'next/image'

export const Logo: React.FC = () => (
  <div className="logo">
    <Image src="/img/logo.png" alt="mydomain.com" width={500} height={250} />
  </div>
)

export const Icon: React.FC = () => (
  <div className="icon">
    <Image src="/img/logo.png" alt="mydomain.com" width={256} height={128} />
  </div>
)

Reproduction Steps

Add the custom Logo and Icon to the payload config file like described above.

Adapters and Plugins

db-mongodb, storage-vercel-blob, form-builder, nested-docs, seo, live-previewrichtext-lexical,

mednet-ecrep avatar Aug 15 '24 09:08 mednet-ecrep

I had similar issues migrating - try looking through the updated documentation for the new way of importing components (the migration guide if not 100% clear on what to do). https://payloadcms.com/docs/beta/admin/components#defining-custom-components-in-the-payload-config

Also remember to but in the importMap config (also not mentioned in the migration guide)

importMap: {
  baseDir: path.resolve(dirname),
}

mikkelwf avatar Aug 15 '24 10:08 mikkelwf

Weird... I just changed it based on the docs and re-generated the importMap:

admin: {
    user: 'admins',
    meta: {
      titleSuffix: '- mypage.com',
    },
    importMap: {
      baseDir: path.resolve(dirname, 'src'),
    },
    components: {
      graphics: {
        Logo: '/payload/graphics/index#Logo',
        Icon: '/payload/graphics/index#Icon',
      },
    },

and still getting this error:

Import trace for requested module:
./src/app/(payload)/layout.tsx
 ⨯ ./src/app/(payload)/admin/importMap.js:28:1
Module not found: Can't resolve 'srcpayloadgraphicsindex'
  26 | import { MetaDescriptionComponent as MetaDescriptionComponent_25 } from '@payloadcms/plugin-seo/client'
  27 | import { PreviewComponent as PreviewComponent_26 } from '@payloadcms/plugin-seo/client'
> 28 | import { Icon as Icon_27 } from 'src\payload\graphics\index'
     | ^
  29 | import { Logo as Logo_28 } from 'src\payload\graphics\index'
  30 |
  31 | export const importMap = {

https://nextjs.org/docs/messages/module-not-found

mednet-ecrep avatar Aug 15 '24 11:08 mednet-ecrep

@mednet-ecrep what's your operating system?

AlessioGr avatar Aug 15 '24 14:08 AlessioGr

@mednet-ecrep what's your operating system?

Windows 11 (DEV), Production on Vercel

mednet-ecrep avatar Aug 15 '24 14:08 mednet-ecrep

Fixed in beta.82 by https://github.com/payloadcms/payload/pull/7706

AlessioGr avatar Aug 15 '24 21:08 AlessioGr

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.

github-actions[bot] avatar Sep 06 '24 21:09 github-actions[bot]