emoji-mart: Runtime error says `D.latestVersion is not a function` in production build by Next.js 13 App Router.

In the prod build, I can’t open the emoji picker, and it throws an error. The information is below.

module.js:781 Uncaught (in promise) TypeError: D.latestVersion is not a function
    at Q (module.js:781:1)
    at Z (module.js:728:1)
    at eQ.connectedCallback (module.js:2918:1)
    at new ep (module.js:1296:1)
    at new ef (module.js:1316:1)
    at new eQ (module.js:2925:1)
    at EmojiPicker.tsx:28:9

The source trace is:

CleanShot 2023-07-21 at 11 24 46@2x

And my code wrote:

({ onEmojiSelect }) => {
  const { data, isLoading } = useQuery({
    queryKey: ['emoji-data'],
    queryFn: () =>
      fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data', {
        next: {
          revalidate: 60 * 60 * 24 * 7,
        },
      }).then((response) => response.json()),

    staleTime: Number.POSITIVE_INFINITY,
  })
  const handleSelect = useCallback((emoji: any) => {
    return onEmojiSelect(emoji.native)
  }, [])

  const handleDivRef = (divEl: HTMLDivElement) => {
    import('emoji-mart').then(
      (m) =>
        new m.Picker({
          ref: {
            current: divEl,
          },
          data,
          onEmojiSelect: handleSelect,
          maxFrequentRows: 0,
        }),
    )
  }

  if (isLoading)
    return (
      <Loading className="flex h-[435px] w-[352px] rounded-md bg-slate-100 center dark:bg-neutral-800" />
    )

  return (
    <div className="w-[352px]">
      <div ref={handleDivRef} />
    </div>
  )
}

That’s not work.

And uses emoji-mart/react like this:

(({ onEmojiSelect }) => {
  const { data, isLoading } = useQuery({
    queryKey: ['emojidata'],
    queryFn: () =>
      fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data', {
        next: {
          revalidate: 60 * 60 * 24 * 7,
        },
      }).then((response) => response.json()),

    staleTime: Infinity,
  })
  const handleSelect = useCallback((emoji: any) => {
    return onEmojiSelect(emoji.native)
  }, [])
  if (isLoading) return <Loading className="w-[352px]" />

  return <Picker data={data} onEmojiSelect={handleSelect} />
})

Also not work in prod.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 11
  • Comments: 21

Most upvoted comments

Just adding swcMinify: false on next.config.js as @tehseenc mentioned fixed the problem

Just adding swcMinify: false on next.config.js as @tehseenc mentioned fixed the problem

It didn’t worked for me Edit: it works

I got it to work with the following (kind of hacky) steps (not sure if any of these are unnecessary).

First I tried adding swcMinify: false into my next.config.js but it did not work, then I removed that and tried the dynamic import for my Picker, this did not work either.

Finally I

  1. Swapped out my init({data}) method at the top of my files to get the data, and instead used this method found in one of the sandboxes provided in this thread: ` data={async () => { const response = await fetch( “https://cdn.jsdelivr.net/npm/@emoji-mart/data/sets/14/native.json” );

    return response.json(); }}`

  2. Then i swapped to using dynamic imports mentioned above. It causes a lag in loading it, especially if its a dropdown so I added this hacky solution to the top of my return in my react components, this way it loads before the drop down opens and does not lag: <div className="hidden"> <Picker /> </div>

  3. I added back the swcMinify: false to my next app and this got it working again! I don’t know if one of these steps is unnecessary but it’s working for now.

You might try dynamic imports, so it will not be bundled. Like. ` import dynamic from ‘next/dynamic’

const Picker = dynamic( () => import(‘emoji-mart’), { ssr: false } )`

at : NextJs Dynamic import

As a workaround I’ve disabled swcMinify in my next.config.js and this error no longer happens.

Looks like this might be a bug with SWC Minifier, rather than emoji-mart.

Hi 👋🏻 What fixed it for me is bumping to "next": "^13.5.4".