Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM interop Nextjs #108

Closed
florianbepunkt opened this issue Dec 5, 2022 · 13 comments
Closed

ESM interop Nextjs #108

florianbepunkt opened this issue Dec 5, 2022 · 13 comments

Comments

@florianbepunkt
Copy link

I'm using this library as part of my own library of shared components, which is imported into a Next.js app. This gives me an ESM error however: Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.

Anyone else experiencing similar problems? I find it quite hard to pinpoint the issue, but it seems that import Sheet from "react-modal-sheet"; is importing it from "dist/index.js" instead of "dist/react-modal-sheet.esm.js"

@Temzasse
Copy link
Owner

Hi 👋🏻 Can you please provide a reproduction case?

@MoOx
Copy link

MoOx commented Jan 26, 2023

Another problem with Next.js 13 is now

error - Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/moox/{project}/node_modules/react-merge-refs/dist/index.mjs not supported.
Instead change the require of /Users/moox/{project}/node_modules/react-merge-refs/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.

So sure, it's related to react-merge-refs, but it's this module calling it. I can't find a solution to be able to compile

@FourLineCode
Copy link

Experiencing the same issue in Next.js 13.

@sujjeee
Copy link

sujjeee commented Jan 28, 2023

hey im also facing same error

Error: require() of ES Module F:\Web Designs\blackrobe\frontend\node_modules\react-merge-refs\dist\index.mjs not supported. Instead change the require of F:\Web Designs\blackrobe\frontend\node_modules\react-merge-refs\dist\index.mjs to a dynamic import() which is available in all CommonJS modules.

@fishuke
Copy link

fishuke commented Jan 30, 2023

I am facing the same problem.

@berendvangaart
Copy link

I'm experiencing the same issue in Nextjs 13

@angelamelinda
Copy link

angelamelinda commented Feb 3, 2023

Facing the same issue in Next.JS 13

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/angela.melinda/Documents/onboarding/project/node_modules/react-merge-refs/dist/index.mjs not supported.
Instead change the require of /Users/angela.melinda/Documents/onboarding/project/node_modules/react-merge-refs/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.

@scroobius-pip
Copy link

Fixed with: experimental.esmExternals: 'loose' in nextjs config file

@angelamelinda
Copy link

I found an alternative way so I could use the library https://kenneho.net/2022/09/03/resolving-error-err_require_esm-require-of-es-module-in-nextjs/

@Knaackee
Copy link

I had the same problem ([email protected], Next.js 13).
I've downgraded to version 1.9.0 which uses an older version of react-merge-refs.

It's now working.

@blackMoja
Copy link
Contributor

blackMoja commented Feb 14, 2023

The same issue occurred for me.
Is there any way to solve it?

The version of react-merge-refs currently being used in the project appears to be 2.0.1.

This library does not seem to support cjs from 2.0.0. 🤔

Link : gregberge/react-merge-refs#17

@husbycodereis
Copy link

downgrading react merge refs as below fixed the issue for me in yarn.lock

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-merge-refs/-/react-merge-refs-1.1.0.tgz#73d88b892c6c68cbb7a66e0800faa374f4c38b06"
integrity sha512-alTKsjEL0dKH/ru1Iyn7vliS2QRcBp9zZPGoWxUOvRGWPUYgjo+V01is7p04It6KhgrzhJGnIj9GgX8W4bZoCQ==

@Temzasse
Copy link
Owner

The react-merge-refs dependency has been removed: https://github.com/Temzasse/react-modal-sheet/releases/tag/v1.10.1

Hopefully it fixes this issue 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests