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.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:23 (2 by maintainers)

github_iconTop GitHub Comments

465reactions
sindresorhuscommented, Jan 10, 2021

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

36reactions
sindresorhuscommented, Apr 30, 2021

@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)

Read more comments on GitHub >

github_iconTop 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 >

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