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.

3.0.0 breaks saying "Must use import to load ES Module"

See original GitHub issue
Full error in Next.js (10.1.3)
Server Error
Error: Must use import to load ES Module: /Users/path/to/node_modules/use-sound/dist/index.js
require() of ES modules is not supported.
require() of /Users/path/to/node_modules/use-sound/dist/index.js from /Users/path/to/.next/server/pages/landing.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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/path/to/node_modules/use-sound/package.json.

FWIW: It starts working as expected when I remove "type": "module" from the package.json

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
joshwcomeaucommented, May 2, 2021

Ah, hm. I tested this on my own Next project and it seemed to work, but I see that I get the same error when I try to build, presumably because it converts the import statements to require.

@jlengstorf let me know if you have any ideas for this, I haven’t kept up with module stuff. Thinking for now I’ll revert this change

0reactions
joshwcomeaucommented, May 3, 2021

3.0.1 removes the type: module field from package.json. I tested on my own Next project and it built, but feel free to let me know if you run into anything else

Read more comments on GitHub >

github_iconTop Results From Across the Web

Must use import to load ES Module · Issue #208 · manuelbieh ...
Hi, Apologies in advance if this is a node issue and not a geolib issue, I'm not familiar with this error message. Up...
Read more >
Importing in Node.js: error "Must use import to load ES Module"
My file is called .mjs then why should it demand the "type": "module" in packages.json, this change breaks other scripts :< I will...
Read more >
err_require_esm ts-node | The AI Search Engine You Control
Error occured when I execute ts-node with file-url@4.0.0 as below: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/taehoon/Desktop/cinesopa- ...
Read more >
The awkward valley to ESM: Node.js, Victory, and D3
ECMAScript Modules ("ESM") offer a new syntax and two means of importing/exporting ... [ERR_REQUIRE_ESM]: Must use import to load ES Module.
Read more >
Error [ERR_REQUIRE_ESM]: Must use import to load ES ...
Instead rename markdownItAttrs.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from ...
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