`node-fetch` incompatibility with latest CommonJS modules' `require()`
Opened this issue · 0 comments
jishanshaikh4 commented
Latest node-fetch
is only compatible with ESM modules. Reverting to old node-fetch would work as long as other vulnerable spots are covered.
Error:
> gitwar@1.0.2 start
> node app.js
Gitwar/utils/fetchTrending.js:2
const fetch = require("node-fetch");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Gitwar/node_modules/node-fetch/src/index.js from /Gitwar/utils/fetchTrending.js not supported.
Instead change the require of index.js in /Gitwar/utils/fetchTrending.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Gitwar/utils/fetchTrending.js:2:15)
at Object.<anonymous> (/Gitwar/routes/top.js:6:31)
at Object.<anonymous> (/Gitwar/app.js:40:19) {
code: 'ERR_REQUIRE_ESM'
}
Reverting to older version of node-fetch should do the job!