3.0.0 breaks saying "Must use import to load ES Module"
See original GitHub issueFull 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:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top 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 >
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
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 torequire
.@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
3.0.1
removes thetype: 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