question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

【Bug Report】"Emoji" component is not working for Next.js

See original GitHub issue

Problem

When “Emoji” Component use with Next.js (SSR), the Error has been occurred like below.

Unhandled Runtime Error TypeError: Class constructor $8b28a44b07620e42$export$2e2bcd8739ae039 cannot be invoked without ‘new’
const Emoji = dynamic<EmojiProps>(
  () => import("emoji-mart").then((m) => m.Emoji),
  {
    ssr: false,
  }
);

export const Foo = () => {
  return (
    <Emoji emoji={"thinking_face"} size={64} />
  );
};

Reference

However, “Picker” component is available for Next.js

const Picker = (props = {}) => {
  const ref = useRef()

  useEffect(() => {
    import('emoji-mart').then((EmojiMart) => {
      new EmojiMart.Picker({ ...props, data, ref })
    })
  }, [])

  return <div ref={ref}/>
}

Example code is here. https://github.com/missive/emoji-mart/issues/575#issuecomment-1111323710

Environment

- next v12.1.6
- Node.js v14.19.0
- TypeScript v4.7.3

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
321ckatz123commented, Jun 21, 2022

Any update on using Emoji directly in React in next (FWIW, this is the same error without using Next.js. Just referencing the Emoji component in React throws the same error).

If we are no longer supposed to use it (looking at the examples, seems like it), can we get an example of the “correct” way to use Emoji inside React?

3reactions
321ckatz123commented, Jun 23, 2022

@EtienneLem FWIW, for your answer to 2, you are describing a relatively common pattern in React that follows the Provider pattern using the internal context library.

To be honest, I kind of have to make it all work in React and your answer to 1 means that I can follow that pattern. Are you amenable to me creating a PR that creates the Provider, Picker, and Emoji React component within this repo?

Also, while I am not the OP, I think this issue can be closed. While yes, this does explode when trying to use it this way, this is a known and expected part of the v5 upgrade and we have answered how to solve it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

image component in next js is not working in development build
Describe the bug. I tried to preview my web app.. in my local machine I was using the image component but the image...
Read more >
Advanced Features: Error Handling - Next.js
Error Handling. This documentation explains how you can handle development, server-side, and client-side errors. Handling Errors in Development.
Read more >
Blog - Next.js 7
Better error reporting with React Error Overlay ... The problem in doing this is that Next.js its URL structure did not match the...
Read more >
Dynamic Imports for Components - Improving your Core Web ...
Let's run another Lighthouse report in Chrome DevTools to verify. We are left with this two optimization suggestions: Use HTTP2: to solve this...
Read more >
module-not-found - Next.js
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found