Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
See original GitHub issueIn Node.js v14, I got this error.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/salty/Documents/src/youtu-bu/node_modules/ky-universal/index.js
require() of ES modules is not supported.
require() of /Users/salty/Documents/src/youtu-bu/node_modules/ky-universal/index.js from /Users/salty/Documents/src/youtu-bu/packages/youtu-bu-sakagura/.next/server/pages/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/salty/Documents/src/youtu-bu/node_modules/ky-universal/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/salty/Documents/src/youtu-bu/node_modules/ky-universal/package.json.
Could you tell me why do you use "type": "module"
in package.json?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:23 (2 by maintainers)
Top Results From Across the Web
Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The error [ERR_REQUIRE_ESM]: require() of ES Module not supported. Instead change the require of index.js to a dynamic import() which is available in...
Read more >Error [ERR_REQUIRE_ESM]: How to use es6 modules in ...
All you have to do is adding the flag --experimental-modules that supports the new es6 import/export statement also the order is important ...
Read more >Error ERR REQUIRE ESM | Must use import to load ES Module
Error ERR REQUIRE ESM | Must use import to load ES Module. 15,379 views15K views. Apr 2, 2021. 46. Dislike. Share. Save.
Read more >Must use import to load ES Module - Netlify Support Forums
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/node_modules/@steeze-ui/heroicons/index.js require() of ES modules is ...
Read more >ERR_REQUIRE_ESM - DEV Community
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ~/projects/semantic-release-toolkit/node_modules/zz/cjs.js require() of ES ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think you could have easily Googled the error and figured this out yourself.
It’s also explained in the release notes: https://github.com/sindresorhus/ky-universal/releases/tag/v0.9.0
@RXminuS I can understand the situation is annoying. Yes, I could have been more helpful in the issue comment, but I get many issues like this every day where the poster did zero effort in Googling or debugging stuff themselves. It’s both time consuming and demotivating.
ky-universal
is a 100% valid ESM package. The fact that Next.js cannot handle ESM is not really something I can control or something I should be obliged to answer support questions about. ESM has been in development for 10 years. We all knew it was coming. Webpack and Next.js could have better prepared for this. In the end, you are the one that chose to use Next.js, with all the hidden complexity that entails.That being said, I’m happy to document workarounds for Next.js in https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c (comment on that gist with any working workarounds)