emoji-mart icon indicating copy to clipboard operation
emoji-mart copied to clipboard

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

Open Innei opened this issue 2 years ago • 21 comments

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.

Innei avatar Jul 21 '23 03:07 Innei

I have the same issue and created a basic sandbox of whats going on https://codesandbox.io/p/sandbox/elated-lake-m6hgwd

It seems to only break in production builds when used with nextjs

kirkegaard avatar Jul 21 '23 12:07 kirkegaard

I'm encountering the same issue with "next": "13.4.10" and "emoji-mart": "^5.5.2"

Alex-ray avatar Jul 21 '23 14:07 Alex-ray

I'm encountering the same issue with "next": "13.2.4" and "emoji-mart": "^5.5.2"

Uncaught (in promise) TypeError: O.latestVersion is not a function

latest

hoseinkord avatar Jul 22 '23 04:07 hoseinkord

I have Error too on "next:"13.4.8" and "emoji-mart": "^5.5.2"

Bravemobin avatar Jul 22 '23 04:07 Bravemobin

Also seeing the same thing

milo- avatar Jul 22 '23 16:07 milo-

Saw the same thing when upgrading to next 13.4.9 in the traditional pages router (not the new app router)

Tagging @EtienneLem to hopefully get some eyes here

Xhale1 avatar Jul 24 '23 17:07 Xhale1

@EtienneLem

hoseinkord avatar Jul 25 '23 06:07 hoseinkord

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.

milo- avatar Jul 25 '23 15:07 milo-

I'm also using the traditional pages router

Alex-ray avatar Jul 26 '23 22:07 Alex-ray

Same issue after upgrading React this week - only in production. Latest version of both React & emoji-mart, using pages router 😢

stevenaanen avatar Jul 27 '23 11:07 stevenaanen

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

donaldboulton avatar Aug 01 '23 06:08 donaldboulton

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

Tried this solution, not working for me, same result. :(

stevenaanen avatar Aug 03 '23 12:08 stevenaanen

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.

tehseenc avatar Aug 03 '23 15:08 tehseenc

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

luantrasel avatar Aug 04 '23 21:08 luantrasel

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

It didn't worked for me Edit: it works

LoryPelli avatar Aug 10 '23 07:08 LoryPelli

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

I used it but it still didn't help much. Please help me.

koniz-dev avatar Sep 17 '23 17:09 koniz-dev

same

brandalx avatar Oct 03 '23 02:10 brandalx

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

PopDaph avatar Oct 03 '23 09:10 PopDaph

This was caused by a problem in @swc/core that was fixed in version 1.3.72.

Issue: https://github.com/swc-project/swc/pull/7702

If you're using SWC, make sure you're on a recent version of @swc/core with a command like:

yarn up -R @swc/core

sirreal avatar Oct 03 '23 12:10 sirreal

Same issue for me. Runtime TypeError: O.latestVersion is not a function. image Next.js 13.4.10, emoji-mart 5.5.2 Not using SWC, so the swcMinify: false fix did nothing to help. Would be grateful for any help with this issue.

Frying7415 avatar Nov 17 '23 11:11 Frying7415

thanks a lot bro @tehseenc that solution is worked 🤙🏻

princebhandarii avatar Mar 18 '24 18:03 princebhandarii