next.js: ERR_ESM_REQUIRE - Webpack 5 config should support ESM packages
What version of Next.js are you using?
10.1.3
What version of Node.js are you using?
14.x
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
p-queue
recently updated to using ESM modules, and it looks like some webpack configuration is required to support it. I doubt this is the last time this particular issue will come up.
Expected Behavior
Users should be able to require ESM modules without getting an error.
To Reproduce
Install p-queue@7.0.0
, import it, and try to start next.
Thanks!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 34
- Comments: 44 (15 by maintainers)
Some background: @sindresorhus is in the process of moving most of his packages to ESM only in 2021. This error will likely become more common as more packages move to ESM only.
I ran into the same issue with https://github.com/sindresorhus/slugify. Workaround: don’t upgrade to latest major.
This is being worked on by @sokra currently, you can check out the initial PR here: https://github.com/vercel/next.js/pull/27069. Do keep in mind this is still work in progress.
not the op, but reproducible with this. both
import
andimport()
fail with:esmExternals: true
is now the default onnext@canary
meaning it is going to be the default in the upcoming stable release. I’m going to close this issue as this particular case has been fixed. For loading ESModules innext.config.js
please subscribe to https://github.com/vercel/next.js/issues/9607.If anyone gets here because of the new
unified
stack, maybe this will save you some time:You can try the latest canary version and verify if it does work in your cases.
For anyone running into similar problems ( @mario-jerkovic ?) that aren’t immediately fixed with next-transpile-modules, you may need to include sub-dependencies in your next.config.js as well. I just ran into this problem with d3-delaunay but it might be present in other d3 modules as well.
Keep an eye on the error messages to see which modules you need to add.
My config looks like:
workaround: use next-transpile-modules
@deadcoder0904 looks like you didn’t actually enable the
esmExternals
config?@deadcoder0904 can you provide a reproduction repository so that we can have a look?
@deadcoder0904 maybe setup issue? I’m using next compose plugins to wrap the transpile,
This config, for latest
rehype-raw
,rehype-slug
andremark-gfm v1.0.0
or maybe you can try NextJS 11.1.0 , and try
no need to use transpile anymore, finally NextJS support it, and it become default in NextJS 12
Can you provide a reproduction? Then we can have a look into it 👍
Same issue with new version of d3 modules like d3-scale