-
Notifications
You must be signed in to change notification settings - Fork 527
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
Unable to use package with Next.js: ERR_REQUIRE_ESM
#1762
Comments
ERR_REQUIRE_ESM
ERR_REQUIRE_ESM
I believe this has to do with an issue related to how Next.js imports modules. A workaround would be to import components individually from the // using import syntax
import Box from '@primer/react/lib/Box'
import Flex from '@primer/react/lib/Flex' |
Ah, I see. Thank you, this workaround works! |
This issue was introduced in |
Hi! Thanks for reporting this, will try to debug this with Next 👍 |
Can confirm this is related to #1700 |
I can confirm this also happens on remix.run |
Took a stab at this since it was relevant for #1771 The core of the problem is that nextjs does not compile anything in node_modules. Technically https://github.com/martpie/next-transpile-modules#readme should solve the problem but it still threw the same error. So I built up @primer/behaviors in a similar manner to @primer/react in the linked PR. It seems to have solved the issue! 🍏 |
Describe the bug
When using this package with next.js (tested 10-12), it fails to build, producing the error
ERR_REQUIRE_ESM
. I have not found a configuration where this issue does not persist.I have also tried adding a custom
.babelrc
with the stock configuration to disable compilation with SWC, but the issue persists.Further Logs
To Reproduce
Steps to reproduce the behavior:
Create a new next.js app using the cli
a.
npx create-next-app@latest --typescript
Cd into the project folder and add this package to the project:
a.
yarn add @primer/react react react-dom styled-components
Replace the contents of
src/_app.tsx
with the following:Snippet
Build the project with
yarn build
, observe console as it fails.Expected behavior
Project builds successfully without errors.
Screenshots
N/A, refer to logs.
Desktop (please complete the following information):
Ubuntu 20.04.3 LTS
N/A
34.1.0
Additional context
package.json
The text was updated successfully, but these errors were encountered: