node-fetch unusable with esm package
See original GitHub issueGiven an index.js file with import fetch from "node-fetch"
When I run cli command node -r esm index.js
Then I should see the script import fetch and run.
Version 3 gives this error.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13) {
code: 'ERR_REQUIRE_ESM'
}
Now, I’ve read the similar threads on this. One thing that hasn’t been mentioned, that the maintainers overlook, is there are still MAJOR projects out there that can’t be used with ESM directly. Cucumber.js is one of them. The top level project must be CJS for cucumber to work, but you can convince it to work seemlessly with the ESM package.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:12
Top Results From Across the Web
ESM only breaks everything · Issue #1263 · node-fetch/node ...
ESM is not ready to have a library as major as node-fetch go ESM only. The workarounds you list in the README will...
Read more >node-fetch@3 Not support in nestjs because it is ESM
I can't use the package "node-fetch@3". I just import it and my console will log the error: const node_fetch_1 = require("node-fetch"); ...
Read more >The Fetch API is finally coming to Node.js - LogRocket Blog
It's been a long time coming, but the Fetch API is now available in Node.js core. Learn why it took so long and...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
Top-level await occurs during the execution phase of the module graph. At this point all resources have already been fetched and linked. There ......
Read more >esm-fetch - npm Package Health Analysis - Snyk
The npm package esm-fetch was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as ......
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 FreeTop 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
Top GitHub Comments
This is extremely opinioned position, which shouldn’t be the case for the lib, as both should be supported, while they are and will be both first-class module systems. A consumer should be able to use the library disregarding of which module system he/she uses. This is even disrespectful to those, who for any of the reasons use cjs.
we also have similar cjs/esm issues open that are basically a dupl of this, so closing this one… There isn’t any issue with node-fetch itself This (now) ESM-only package works as intended. if you have a problem with using ESM-only packages or any other solution highlighted in #1227 then it’s really up to you to fix it
There is also a discussion about having a exposed cjs file that only export fetch (not headers, Response and Request) that is related to this: #1327